mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using MyCore.Models;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MongoDB.Driver;
|
|
|
|
namespace MyCore.Services
|
|
{
|
|
public class ScreenDeviceService
|
|
{
|
|
private readonly IMongoCollection<ScreenDevice> _screenDevices;
|
|
|
|
public ScreenDeviceService(IConfiguration config)
|
|
{
|
|
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
|
var database = client.GetDatabase("MyCoreDb");
|
|
_screenDevices = database.GetCollection<ScreenDevice>("ScreenDevices");
|
|
}
|
|
|
|
public List<ScreenDevice> GetAll()
|
|
{
|
|
return _screenDevices.Find(m => true).ToList();
|
|
}
|
|
|
|
public ScreenDevice GetInfo(string id)
|
|
{
|
|
return _screenDevices.Find<ScreenDevice>(m => m.Id == id).FirstOrDefault();
|
|
}
|
|
|
|
public ScreenDevice Create(ScreenDevice device)
|
|
{
|
|
_screenDevices.InsertOne(device);
|
|
return device;
|
|
}
|
|
|
|
public void Update(string id, ScreenDevice screenDeviceIn)
|
|
{
|
|
_screenDevices.ReplaceOne(screenDevice => screenDevice.Id == id, screenDeviceIn);
|
|
}
|
|
|
|
public void Remove(ScreenDevice screenDeviceIn)
|
|
{
|
|
_screenDevices.DeleteOne(screenDevice => screenDevice.Id == screenDeviceIn.Id);
|
|
}
|
|
|
|
public void Remove(string id)
|
|
{
|
|
_screenDevices.DeleteOne(screenDevice => screenDevice.Id == id);
|
|
}
|
|
}
|
|
}
|