mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
MC Change files structure + add Device, Location, Provider, Group, Information and Automation (Models & Services) + Change device to screenDevice etc
This commit is contained in:
parent
15a758fccf
commit
3f8a519adb
@ -1,95 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using MongoDB.Bson;
|
|
||||||
using MyCore.Models;
|
|
||||||
using MyCore.Services;
|
|
||||||
|
|
||||||
namespace MyCore.Controllers
|
|
||||||
{
|
|
||||||
[Authorize(Roles = "Admin")]
|
|
||||||
[Route("api/device")]
|
|
||||||
[ApiController]
|
|
||||||
public class DeviceController : ControllerBase
|
|
||||||
{
|
|
||||||
private readonly DeviceService _DeviceService;
|
|
||||||
|
|
||||||
public DeviceController(DeviceService DeviceService)
|
|
||||||
{
|
|
||||||
_DeviceService = DeviceService;
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: Devices
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
[HttpGet]
|
|
||||||
public ActionResult<List<Device>> GetAllDevices()
|
|
||||||
{
|
|
||||||
return _DeviceService.GetAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: Device
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idDevice">Id of the device you want to get information</param>
|
|
||||||
[HttpGet("{idDevice}")]
|
|
||||||
public ActionResult<Device> GetDeviceInfo(string idDevice)
|
|
||||||
{
|
|
||||||
return _DeviceService.GetDeviceInfo(idDevice);
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: Device/Create
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
[HttpPost]
|
|
||||||
public IActionResult CreateDevice(int idDevice, [FromBody] Device device)
|
|
||||||
{
|
|
||||||
if (idDevice == 0)
|
|
||||||
{
|
|
||||||
_DeviceService.CreateDevice(device);
|
|
||||||
|
|
||||||
return StatusCode(201);
|
|
||||||
}
|
|
||||||
return StatusCode(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
// PUT: Device/Update
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
[HttpPut("{idDevice}")]
|
|
||||||
public IActionResult UpdateDevice(int idDevice, [FromBody] Device device)
|
|
||||||
{
|
|
||||||
if (idDevice == 0)
|
|
||||||
{
|
|
||||||
_DeviceService.Update(device.Id, device);
|
|
||||||
|
|
||||||
return StatusCode(201);
|
|
||||||
}
|
|
||||||
return StatusCode(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete: Device/Delete
|
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
[HttpDelete("{idDevice}")]
|
|
||||||
public IActionResult DeleteDevice(int idDevice, [FromBody] string deviceId)
|
|
||||||
{
|
|
||||||
if (idDevice == 0)
|
|
||||||
{
|
|
||||||
_DeviceService.Remove(deviceId);
|
|
||||||
|
|
||||||
return StatusCode(201);
|
|
||||||
}
|
|
||||||
return StatusCode(500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
67
MyCore/Controllers/Devices/IoThomas/EnergyController.cs
Normal file
67
MyCore/Controllers/Devices/IoThomas/EnergyController.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MQTTnet;
|
||||||
|
using MQTTnet.Client;
|
||||||
|
using MQTTnet.Server;
|
||||||
|
using MyCore.DTO.Energy;
|
||||||
|
using MyCore.Models;
|
||||||
|
using MyCore.Models.Energy;
|
||||||
|
using MyCore.Services;
|
||||||
|
using static MyCore.Services.OddService;
|
||||||
|
|
||||||
|
namespace MyCore.Controllers
|
||||||
|
{
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
|
[Route("api/energy")]
|
||||||
|
[ApiController]
|
||||||
|
public class EnergyController : ControllerBase
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly EnergyService _EnergyService;
|
||||||
|
|
||||||
|
public EnergyController(EnergyService energyService)
|
||||||
|
{
|
||||||
|
_EnergyService = energyService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET api/energy/electricity/year
|
||||||
|
/// <summary>
|
||||||
|
/// Get summary production of Kwh/Year
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("electricity")]
|
||||||
|
public ActionResult<List<ElectricityProduction>> GetElectricityProduction(string userId, ViewBy viewBy)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
switch (viewBy)
|
||||||
|
{
|
||||||
|
case ViewBy.Year:
|
||||||
|
return _EnergyService.GetElectricityProductionForSpecifiedYear(userId, DateTime.Now.Year);
|
||||||
|
break;
|
||||||
|
case ViewBy.Month:
|
||||||
|
return _EnergyService.GetElectricityProductionForSpecifiedMonth(userId, DateTime.Now.Month);
|
||||||
|
break;
|
||||||
|
case ViewBy.Day:
|
||||||
|
return _EnergyService.GetElectricityProductionForSpecifiedDay(userId, DateTime.Now.DayOfYear);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return new ObjectResult("Error - ViewBy incorrect") { StatusCode = 500 };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
|
||||||
|
return new ObjectResult("Error - TODO") { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
124
MyCore/Controllers/Devices/ScreenDeviceController.cs
Normal file
124
MyCore/Controllers/Devices/ScreenDeviceController.cs
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
using MyCore.Models;
|
||||||
|
using MyCore.Services;
|
||||||
|
|
||||||
|
namespace MyCore.Controllers
|
||||||
|
{
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
|
[Route("api/device/screen")]
|
||||||
|
[ApiController]
|
||||||
|
public class ScreenDeviceController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ScreenDeviceService _ScreenDeviceService;
|
||||||
|
|
||||||
|
public ScreenDeviceController(ScreenDeviceService ScreenDeviceService)
|
||||||
|
{
|
||||||
|
_ScreenDeviceService = ScreenDeviceService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: Devices
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[ProducesResponseType(typeof(List<ScreenDevice>), 200)]
|
||||||
|
[HttpGet]
|
||||||
|
public ObjectResult GetAllScreenDevices()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<ScreenDevice> screenDevices = _ScreenDeviceService.GetAll();
|
||||||
|
|
||||||
|
return new OkObjectResult(screenDevices);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: ScreenDevice
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idScreenDevice">Id of the screen device you want to get information</param>
|
||||||
|
[ProducesResponseType(typeof(ScreenDevice), 200)]
|
||||||
|
[HttpGet("{idScreenDevice}")]
|
||||||
|
public ObjectResult GetDeviceInfo(string idScreenDevice)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ScreenDevice screenDevice = _ScreenDeviceService.GetInfo(idScreenDevice);
|
||||||
|
|
||||||
|
return new OkObjectResult(screenDevice);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: Device/Create
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost]
|
||||||
|
public ObjectResult CreateDevice([FromBody] ScreenDevice screenDevice)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ScreenDeviceService.Create(screenDevice);
|
||||||
|
|
||||||
|
return new OkObjectResult(201);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT: Device/Update
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[HttpPut("{idScreenDevice}")]
|
||||||
|
public ObjectResult UpdateDevice(int idScreenDevice, [FromBody] ScreenDevice screenDevice)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ScreenDeviceService.Update(screenDevice.Id, screenDevice);
|
||||||
|
|
||||||
|
return new OkObjectResult(201);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete: Device/Delete
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
[HttpDelete("{idDevice}")]
|
||||||
|
public ObjectResult DeleteDevice(int idDevice, [FromBody] string deviceId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ScreenDeviceService.Remove(deviceId);
|
||||||
|
|
||||||
|
return new OkObjectResult(201);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -30,6 +30,13 @@ namespace MyCore.Controllers
|
|||||||
{
|
{
|
||||||
List<PanelSection> panelSectionList = new List<PanelSection>();
|
List<PanelSection> panelSectionList = new List<PanelSection>();
|
||||||
|
|
||||||
|
// Main view
|
||||||
|
/*PanelSection panelSectionMain = new PanelSection();
|
||||||
|
panelSectionMain.Label = "Main";
|
||||||
|
panelSectionMain.Icon = "fas fa-eye";
|
||||||
|
panelSectionMain.DefaultRoute = "main";
|
||||||
|
panelSectionMain.Color = "red";*/
|
||||||
|
|
||||||
// Energy
|
// Energy
|
||||||
PanelSection panelSectionEnergy = new PanelSection();
|
PanelSection panelSectionEnergy = new PanelSection();
|
||||||
panelSectionEnergy.Label = "Energy";
|
panelSectionEnergy.Label = "Energy";
|
||||||
14
MyCore/DTO/Common/ConnectionStatus.cs
Normal file
14
MyCore/DTO/Common/ConnectionStatus.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MyCore.DTO.Common
|
||||||
|
{
|
||||||
|
public enum ConnectionStatus
|
||||||
|
{
|
||||||
|
Connected = 1,
|
||||||
|
Disconnected,
|
||||||
|
Unknown
|
||||||
|
}
|
||||||
|
}
|
||||||
15
MyCore/DTO/Common/MeansOfCommunication.cs
Normal file
15
MyCore/DTO/Common/MeansOfCommunication.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MyCore.DTO.Common
|
||||||
|
{
|
||||||
|
public enum MeansOfCommunication
|
||||||
|
{
|
||||||
|
Wifi = 1,
|
||||||
|
Bluetooth,
|
||||||
|
Zigbee,
|
||||||
|
Zwave
|
||||||
|
}
|
||||||
|
}
|
||||||
14
MyCore/DTO/Common/ViewBy.cs
Normal file
14
MyCore/DTO/Common/ViewBy.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MyCore.DTO.Energy
|
||||||
|
{
|
||||||
|
public enum ViewBy
|
||||||
|
{
|
||||||
|
Year = 1,
|
||||||
|
Month,
|
||||||
|
Day
|
||||||
|
}
|
||||||
|
}
|
||||||
33
MyCore/Models/Common/LogDatabase.cs
Normal file
33
MyCore/Models/Common/LogDatabase.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MyCore.Models.Common
|
||||||
|
{
|
||||||
|
public class LogDatabase // TODO
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Time")]
|
||||||
|
public DateTime Time { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Level")]
|
||||||
|
public int Level { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Message")]
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Sent")]
|
||||||
|
public bool Sent { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,20 +1,34 @@
|
|||||||
using System;
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MyCore.DTO.Common;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MyCore.Models
|
namespace MyCore.Models
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Automation
|
||||||
|
/// </summary>
|
||||||
public class Automation
|
public class Automation
|
||||||
{
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Name")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public List<Declencheur> Declencheurs { get; set; }
|
|
||||||
|
[BsonElement("Triggers")]
|
||||||
|
public List<Trigger> Triggers { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Conditions")]
|
||||||
public List<Condition> Conditions { get; set; }
|
public List<Condition> Conditions { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Actions")]
|
||||||
public List<Action> Actions { get; set; }
|
public List<Action> Actions { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Declencheur
|
public class Trigger
|
||||||
{
|
{
|
||||||
public enum Type
|
public enum Type
|
||||||
{
|
{
|
||||||
57
MyCore/Models/MyControlPanel/Device.cs
Normal file
57
MyCore/Models/MyControlPanel/Device.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MyCore.DTO.Common;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace MyCore.Models.MyControlPanel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Group of devices
|
||||||
|
/// </summary>
|
||||||
|
public class Device
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("ConnectionStatus")]
|
||||||
|
public ConnectionStatus ConnectionStatus { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Location")]
|
||||||
|
public Location Location { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("MeansOfCommunications")]
|
||||||
|
public List<MeansOfCommunication> MeansOfCommunications { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("CreatedDate")]
|
||||||
|
public DateTime CreatedDate { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("UpdatedDate")]
|
||||||
|
public DateTime UpdatedDate { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("LastMessage")]
|
||||||
|
public string LastMessage { get; set; } // TODO UNIFORMISATION ?
|
||||||
|
|
||||||
|
[BsonElement("LastMessageDate")]
|
||||||
|
public DateTime LastMessageDate { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Battery")]
|
||||||
|
public bool Battery { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("BatteryStatus")]
|
||||||
|
public int BatteryStatus { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Provider")]
|
||||||
|
public Provider provider { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Groups")]
|
||||||
|
public List<Group> Groups { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Informations")]
|
||||||
|
public List<Information> Informations { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
23
MyCore/Models/MyControlPanel/Group.cs
Normal file
23
MyCore/Models/MyControlPanel/Group.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MyCore.DTO.Common;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
namespace MyCore.Models.MyControlPanel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Group of devices
|
||||||
|
/// </summary>
|
||||||
|
public class Group
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Devices")]
|
||||||
|
public List<Device> Devices { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
24
MyCore/Models/MyControlPanel/Information.cs
Normal file
24
MyCore/Models/MyControlPanel/Information.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MyCore.DTO.Common;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace MyCore.Models.MyControlPanel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Information contains in device message
|
||||||
|
/// </summary>
|
||||||
|
public class Information
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Value")]
|
||||||
|
public object Value { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
18
MyCore/Models/MyControlPanel/Location.cs
Normal file
18
MyCore/Models/MyControlPanel/Location.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
|
||||||
|
namespace MyCore.Models.MyControlPanel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Location of a device (Room name, garden, ..)
|
||||||
|
/// </summary>
|
||||||
|
public class Location
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
30
MyCore/Models/MyControlPanel/Provider.cs
Normal file
30
MyCore/Models/MyControlPanel/Provider.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MyCore.DTO.Common;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace MyCore.Models.MyControlPanel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provider of a device (provider of informations) - e.g. : Meross, Arlo, IoThomas, ...
|
||||||
|
/// </summary>
|
||||||
|
public class Provider
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Username")]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Password")]
|
||||||
|
public string Password { get; set; } // TODO ENCRYPTED
|
||||||
|
|
||||||
|
[BsonElement("ApiKey")]
|
||||||
|
public string ApiKey { get; set; } // TODO ENCRYPTED
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,9 +5,13 @@ using System.Threading.Tasks;
|
|||||||
using AspNetCore.Security.Jwt;
|
using AspNetCore.Security.Jwt;
|
||||||
using MongoDB.Bson;
|
using MongoDB.Bson;
|
||||||
using MongoDB.Bson.Serialization.Attributes;
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using MyCore.Models.MyControlPanel;
|
||||||
|
|
||||||
namespace MyCore.Models
|
namespace MyCore.Models
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// User Information
|
||||||
|
/// </summary>
|
||||||
public class UserInfo : IAuthenticationUser
|
public class UserInfo : IAuthenticationUser
|
||||||
{
|
{
|
||||||
[BsonId]
|
[BsonId]
|
||||||
@ -59,11 +63,24 @@ namespace MyCore.Models
|
|||||||
[BsonElement("PostalCode")]
|
[BsonElement("PostalCode")]
|
||||||
public int PostalCode { get; set; }
|
public int PostalCode { get; set; }
|
||||||
|
|
||||||
[BsonElement("ScreenConfigurationIds")]
|
[BsonElement("Automations")]
|
||||||
|
public Automation[] Automations { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Devices")]
|
||||||
|
public Device[] Devices { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Providers")]
|
||||||
|
public Provider[] Providers { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Groups")]
|
||||||
|
public Group[] Groups { get; set; }
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
/*[BsonElement("ScreenConfigurationIds")]
|
||||||
public ScreenConfiguration[] ScreenConfigurationIds { get; set; }
|
public ScreenConfiguration[] ScreenConfigurationIds { get; set; }
|
||||||
|
|
||||||
[BsonElement("DeviceIds")]
|
[BsonElement("DeviceIds")]
|
||||||
public Device[] DeviceIds { get; set; }
|
public ScreenDevice[] DeviceIds { get; set; }*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
using MongoDB.Bson;
|
||||||
|
using MongoDB.Bson.Serialization.Attributes;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MyCore.Models.Energy
|
||||||
|
{
|
||||||
|
public class ElectricityProduction
|
||||||
|
{
|
||||||
|
[BsonId]
|
||||||
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("DeviceId")]
|
||||||
|
public string DeviceId { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("UserId")]
|
||||||
|
public string UserId { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Watt")]
|
||||||
|
public double Watt { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Ampere")]
|
||||||
|
public double Ampere { get; set; }
|
||||||
|
|
||||||
|
[BsonElement("Timestamp")]
|
||||||
|
public DateTime Timestamp { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace MyCore.Models
|
namespace MyCore.Models
|
||||||
{
|
{
|
||||||
public class Device
|
public class ScreenDevice
|
||||||
{
|
{
|
||||||
[BsonId]
|
[BsonId]
|
||||||
[BsonRepresentation(BsonType.ObjectId)]
|
[BsonRepresentation(BsonType.ObjectId)]
|
||||||
@ -26,10 +26,10 @@ namespace MyCore.Models
|
|||||||
public string LocationExplanation { get; set; }
|
public string LocationExplanation { get; set; }
|
||||||
|
|
||||||
[BsonElement("Height")]
|
[BsonElement("Height")]
|
||||||
public int Height { get; set; }
|
public int Height { get; set; } // ?
|
||||||
|
|
||||||
[BsonElement("Width")]
|
[BsonElement("Width")]
|
||||||
public int Width { get; set; }
|
public int Width { get; set; } // ?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
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 DeviceService
|
|
||||||
{
|
|
||||||
private readonly IMongoCollection<Device> _devices;
|
|
||||||
|
|
||||||
public DeviceService(IConfiguration config)
|
|
||||||
{
|
|
||||||
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
|
||||||
var database = client.GetDatabase("MyCoreDb");
|
|
||||||
_devices = database.GetCollection<Device>("Devices");
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Device> GetAll()
|
|
||||||
{
|
|
||||||
return _devices.Find(m => true).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Device GetDeviceInfo(string id)
|
|
||||||
{
|
|
||||||
return _devices.Find<Device>(m => m.Id == id).FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Device CreateDevice(Device device)
|
|
||||||
{
|
|
||||||
_devices.InsertOne(device);
|
|
||||||
return device;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(string id, Device deviceIn)
|
|
||||||
{
|
|
||||||
_devices.ReplaceOne(device => device.Id == id, deviceIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Remove(Device deviceIn)
|
|
||||||
{
|
|
||||||
_devices.DeleteOne(device => device.Id == deviceIn.Id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Remove(string id)
|
|
||||||
{
|
|
||||||
_devices.DeleteOne(device => device.Id == id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
85
MyCore/Services/Devices/IoThomas/EnergyService.cs
Normal file
85
MyCore/Services/Devices/IoThomas/EnergyService.cs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MyCore.Models;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using MyCore.Models.Energy;
|
||||||
|
|
||||||
|
namespace MyCore.Services
|
||||||
|
{
|
||||||
|
public class EnergyService
|
||||||
|
{
|
||||||
|
private readonly IMongoCollection<ElectricityProduction> _electricityProductionData;
|
||||||
|
|
||||||
|
public EnergyService(IConfiguration config)
|
||||||
|
{
|
||||||
|
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
||||||
|
var database = client.GetDatabase("MyCoreDb");
|
||||||
|
_electricityProductionData = database.GetCollection<ElectricityProduction>("ElectricityProduction");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ElectricityProduction> GetAll()
|
||||||
|
{
|
||||||
|
return _electricityProductionData.Find(m => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ElectricityProduction> GetElectricityProductionForSpecifiedYear(string userId, int year)
|
||||||
|
{
|
||||||
|
return _electricityProductionData.Find<ElectricityProduction>(m => m.UserId == userId && m.Timestamp.Year == year).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ElectricityProduction> GetElectricityProductionForSpecifiedMonth(string userId, int month)
|
||||||
|
{
|
||||||
|
return _electricityProductionData.Find<ElectricityProduction>(m => m.UserId == userId && m.Timestamp.Month == month).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ElectricityProduction> GetElectricityProductionForSpecifiedDay(string userId, int dayOfYear)
|
||||||
|
{
|
||||||
|
return _electricityProductionData.Find<ElectricityProduction>(m => m.UserId == userId && m.Timestamp.DayOfYear == dayOfYear).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if necessary
|
||||||
|
public ElectricityProduction GetElectricityProductionForUser(string userId)
|
||||||
|
{
|
||||||
|
return _electricityProductionData.Find<ElectricityProduction>(m => m.UserId == userId).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ElectricityProduction InsertData(ElectricityProduction data)
|
||||||
|
{
|
||||||
|
_electricityProductionData.InsertOne(data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if necessary
|
||||||
|
public void Update(string id, ElectricityProduction dataIn)
|
||||||
|
{
|
||||||
|
_electricityProductionData.ReplaceOne(data => data.Id == id, dataIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if necessary
|
||||||
|
public void Remove(ElectricityProduction dataIn)
|
||||||
|
{
|
||||||
|
_electricityProductionData.DeleteOne(data => data.Id == dataIn.Id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if necessary
|
||||||
|
public void Remove(string id)
|
||||||
|
{
|
||||||
|
_electricityProductionData.DeleteOne(data => data.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if necessary
|
||||||
|
public void RemoveByDeviceId(string userId, string id)
|
||||||
|
{
|
||||||
|
_electricityProductionData.DeleteOne(data => data.UserId == userId && data.DeviceId == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if necessary
|
||||||
|
public void RemoveByDeviceIdBeforeDate(string userId, DateTime dateTime)
|
||||||
|
{
|
||||||
|
_electricityProductionData.DeleteOne(data => data.UserId == userId && data.Timestamp < dateTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
53
MyCore/Services/Devices/ScreenDeviceService.cs
Normal file
53
MyCore/Services/Devices/ScreenDeviceService.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
MyCore/Services/MyControlPanel/AutomationService.cs
Normal file
49
MyCore/Services/MyControlPanel/AutomationService.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MyCore.Models;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using MyCore.Models.MyControlPanel;
|
||||||
|
|
||||||
|
namespace MyCore.Services.MyControlPanel
|
||||||
|
{
|
||||||
|
public class AutomationService
|
||||||
|
{
|
||||||
|
private readonly IMongoCollection<Automation> _Automations;
|
||||||
|
|
||||||
|
public AutomationService(IConfiguration config)
|
||||||
|
{
|
||||||
|
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
||||||
|
var database = client.GetDatabase("MyCoreDb");
|
||||||
|
_Automations = database.GetCollection<Automation>("Automations");
|
||||||
|
}
|
||||||
|
public List<Automation> GetAutomations()
|
||||||
|
{
|
||||||
|
return _Automations.Find(d => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Automation GetAutomationById(string id)
|
||||||
|
{
|
||||||
|
return _Automations.Find<Automation>(a => a.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Automation CreateAutomation(Automation automation)
|
||||||
|
{
|
||||||
|
_Automations.InsertOne(automation);
|
||||||
|
return automation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Automation Update(string id, Automation automationIn)
|
||||||
|
{
|
||||||
|
_Automations.ReplaceOne(automation => automation.Id == id, automationIn);
|
||||||
|
return automationIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(string id)
|
||||||
|
{
|
||||||
|
_Automations.DeleteOne(automation => automation.Id == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
MyCore/Services/MyControlPanel/DeviceService.cs
Normal file
49
MyCore/Services/MyControlPanel/DeviceService.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MyCore.Models;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using MyCore.Models.MyControlPanel;
|
||||||
|
|
||||||
|
namespace MyCore.Services.MyControlPanel
|
||||||
|
{
|
||||||
|
public class DeviceService
|
||||||
|
{
|
||||||
|
private readonly IMongoCollection<Device> _Devices;
|
||||||
|
|
||||||
|
public DeviceService(IConfiguration config)
|
||||||
|
{
|
||||||
|
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
||||||
|
var database = client.GetDatabase("MyCoreDb");
|
||||||
|
_Devices = database.GetCollection<Device>("Devices");
|
||||||
|
}
|
||||||
|
public List<Device> GetDevices()
|
||||||
|
{
|
||||||
|
return _Devices.Find(d => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Device GetDeviceById(string id)
|
||||||
|
{
|
||||||
|
return _Devices.Find<Device>(d => d.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Device CreateDevice(Device device)
|
||||||
|
{
|
||||||
|
_Devices.InsertOne(device);
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Device Update(string id, Device deviceIn)
|
||||||
|
{
|
||||||
|
_Devices.ReplaceOne(device => device.Id == id, deviceIn);
|
||||||
|
return deviceIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(string id)
|
||||||
|
{
|
||||||
|
_Devices.DeleteOne(device => device.Id == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
49
MyCore/Services/MyControlPanel/GroupService.cs
Normal file
49
MyCore/Services/MyControlPanel/GroupService.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MyCore.Models;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using MyCore.Models.MyControlPanel;
|
||||||
|
|
||||||
|
namespace MyCore.Services.MyControlPanel
|
||||||
|
{
|
||||||
|
public class GroupService
|
||||||
|
{
|
||||||
|
private readonly IMongoCollection<Group> _Groups;
|
||||||
|
|
||||||
|
public GroupService(IConfiguration config)
|
||||||
|
{
|
||||||
|
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
||||||
|
var database = client.GetDatabase("MyCoreDb");
|
||||||
|
_Groups = database.GetCollection<Group>("Groups");
|
||||||
|
}
|
||||||
|
public List<Group> GetGroups()
|
||||||
|
{
|
||||||
|
return _Groups.Find(d => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group GetGroupById(string id)
|
||||||
|
{
|
||||||
|
return _Groups.Find<Group>(g => g.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group CreateGroup(Group group)
|
||||||
|
{
|
||||||
|
_Groups.InsertOne(group);
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group Update(string id, Group groupIn)
|
||||||
|
{
|
||||||
|
_Groups.ReplaceOne(group => group.Id == id, groupIn);
|
||||||
|
return groupIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(string id)
|
||||||
|
{
|
||||||
|
_Groups.DeleteOne(group => group.Id == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
MyCore/Services/MyControlPanel/LocationService.cs
Normal file
11
MyCore/Services/MyControlPanel/LocationService.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MyCore.Services.MyControlPanel
|
||||||
|
{
|
||||||
|
public class LocationService
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
48
MyCore/Services/MyControlPanel/ProviderService.cs
Normal file
48
MyCore/Services/MyControlPanel/ProviderService.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using MyCore.Models;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using MyCore.Models.MyControlPanel;
|
||||||
|
namespace MyCore.Services.MyControlPanel
|
||||||
|
{
|
||||||
|
public class ProviderService
|
||||||
|
{
|
||||||
|
private readonly IMongoCollection<Provider> _Providers;
|
||||||
|
|
||||||
|
public ProviderService(IConfiguration config)
|
||||||
|
{
|
||||||
|
var client = new MongoClient(config.GetConnectionString("MyCoreDb"));
|
||||||
|
var database = client.GetDatabase("MyCoreDb");
|
||||||
|
_Providers = database.GetCollection<Provider>("Providers");
|
||||||
|
}
|
||||||
|
public List<Provider> GetProviders()
|
||||||
|
{
|
||||||
|
return _Providers.Find(p => true).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Provider GetProviderById(string id)
|
||||||
|
{
|
||||||
|
return _Providers.Find<Provider>(p => p.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Provider CreateProvider(Provider provider)
|
||||||
|
{
|
||||||
|
_Providers.InsertOne(provider);
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Provider Update(string id, Provider providerIn)
|
||||||
|
{
|
||||||
|
_Providers.ReplaceOne(provider => provider.Id == id, providerIn);
|
||||||
|
return providerIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Remove(string id)
|
||||||
|
{
|
||||||
|
_Providers.DeleteOne(provider => provider.Id == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user