mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 17:51:20 +00:00
56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using MyCore.Models;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MongoDB.Driver;
|
|
|
|
namespace MyCore.Services
|
|
{
|
|
public class IoTDeviceService
|
|
{
|
|
private readonly IMongoCollection<SmartPrinterMessage> _SmartPrinterMessages;
|
|
|
|
public IoTDeviceService(IConfiguration config)
|
|
{
|
|
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
|
var database = client.GetDatabase("MyCoreDb");
|
|
_SmartPrinterMessages = database.GetCollection<SmartPrinterMessage> ("IoTDevices");
|
|
}
|
|
|
|
public List<SmartPrinterMessage> Get()
|
|
{
|
|
return _SmartPrinterMessages.Find(m => true).ToList();
|
|
}
|
|
|
|
public SmartPrinterMessage Get(string id)
|
|
{
|
|
return _SmartPrinterMessages.Find<SmartPrinterMessage>(m => m.Id == id).FirstOrDefault();
|
|
}
|
|
|
|
public SmartPrinterMessage Create(SmartPrinterMessage message)
|
|
{
|
|
_SmartPrinterMessages.InsertOne(message);
|
|
return message;
|
|
}
|
|
|
|
/*public void Update(string id, Book bookIn)
|
|
{
|
|
_books.ReplaceOne(book => book.Id == id, bookIn);
|
|
}
|
|
|
|
public void Remove(Book bookIn)
|
|
{
|
|
_books.DeleteOne(book => book.Id == bookIn.Id);
|
|
}
|
|
|
|
public void Remove(string id)
|
|
{
|
|
_books.DeleteOne(book => book.Id == id);
|
|
}*/
|
|
}
|
|
}
|