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 _screenDevices; public ScreenDeviceService(IConfiguration config) { var client = new MongoClient(config.GetConnectionString("MyCoreDb")); var database = client.GetDatabase("MyCoreDb"); _screenDevices = database.GetCollection("ScreenDevices"); } public List GetAll() { return _screenDevices.Find(m => true).ToList(); } public ScreenDevice GetInfo(string id) { return _screenDevices.Find(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); } } }