MC Update deviceController support for meross, arlo and yeelight devices

This commit is contained in:
Thomas Fransolet 2020-03-31 18:25:30 +02:00
parent 8934a860fc
commit 28903e1a16
10 changed files with 182 additions and 61 deletions

View File

@ -41,16 +41,22 @@ namespace MyCore.Controllers.Devices
/// <summary>
/// Get all devices summary
/// </summary>
/// <param name="userId">Id of user</param>
[ProducesResponseType(typeof(List<DeviceSummaryDTO>), 200)]
[HttpGet]
public ObjectResult GetAll()
public ObjectResult GetAll(string userId)
{
try
{
List<Device> Devices = _DeviceDatabaseService.GetAll();
List<Device> Devices = _DeviceDatabaseService.GetAll(userId);
List<DeviceSummaryDTO> devicesSummaryDTO = Devices.Select(d => d.ToSummaryDTO()).ToList();
foreach (var device in devicesSummaryDTO)
{
device.ProviderName = _ProviderDatabaseService.GetById(userId, device.ProviderId).Name;
}
return new OkObjectResult(devicesSummaryDTO);
}
catch (Exception ex)
@ -62,10 +68,11 @@ namespace MyCore.Controllers.Devices
/// <summary>
/// Get a specific device info
/// </summary>
/// <param name="userId">Id of user</param>
/// <param name="deviceId">id of device</param>
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
[HttpGet("{deviceId}")]
public ObjectResult GetDetail(string deviceId)
public ObjectResult GetDetail(string userId, string deviceId)
{
try
{
@ -89,11 +96,10 @@ namespace MyCore.Controllers.Devices
{
try
{
if (deviceDetailDTO == null)
throw new KeyNotFoundException("Device is null");
DeviceDetailDTO deviceCreated = DeviceService.CreateOrUpdate(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, deviceDetailDTO, true);
DeviceDetailDTO deviceCreated = DeviceService.CreateOrUpdate(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, deviceDetailDTO.UserId, deviceDetailDTO, true);
return new OkObjectResult(deviceCreated);
@ -133,7 +139,7 @@ namespace MyCore.Controllers.Devices
if (provider == null)
throw new KeyNotFoundException("Provider id is null");
List<DeviceDetailDTO> devicesCreated = await DeviceService.CreateFromProvider(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, provider);
List<DeviceDetailDTO> devicesCreated = await DeviceService.CreateFromProvider(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, userId, provider);
return new OkObjectResult(devicesCreated);
}
@ -162,18 +168,18 @@ namespace MyCore.Controllers.Devices
/// <summary>
/// Update a device
/// </summary>
/// <param name="deviceId">Device Id</param>
/// <param name="userId">Device Id</param>
/// <param name="deviceDetailDTO">Device to update</param>
[ProducesResponseType(typeof(DeviceDetailDTO), 200)]
[HttpPut("{deviceId}")]
public ObjectResult Update(string deviceId, [FromBody] DeviceDetailDTO deviceDetailDTO)
public ObjectResult Update(string userId, [FromBody] DeviceDetailDTO deviceDetailDTO)
{
try
{
if (!_DeviceDatabaseService.IsExist(deviceId))
if (!_DeviceDatabaseService.IsExist(deviceDetailDTO.Id))
throw new KeyNotFoundException("Device does not exist");
DeviceDetailDTO deviceUpdated = DeviceService.CreateOrUpdate(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, deviceDetailDTO, false);
DeviceDetailDTO deviceUpdated = DeviceService.CreateOrUpdate(this._DeviceDatabaseService, this._ProviderDatabaseService, this._LocationDatabaseService, userId, deviceDetailDTO, false);
return new OkObjectResult(deviceUpdated);
}
@ -206,5 +212,25 @@ namespace MyCore.Controllers.Devices
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
/// <summary>
/// Delete a device
/// </summary>
/// <param name="userId">Id of user</param>
[HttpDelete("user/{userId}")]
public ObjectResult DeleteAllForUser(string userId)
{
try
{
// Check if exist
_DeviceDatabaseService.RemoveForUser(userId);
return new OkObjectResult(201);
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };
}
}
}
}

View File

@ -93,6 +93,9 @@ namespace MyCore.Controllers.Devices
if (providerDTO == null)
throw new KeyNotFoundException("Provider is null");
if (_ProviderDatabaseService.AlreadyExistForUser(userId, providerDTO.Name))
throw new ArgumentException("Provider already exists");
ProviderDTO providerCreated = ProviderService.CreateOrUpdate(this._ProviderDatabaseService, userId, providerDTO, true);
return new OkObjectResult(providerCreated);
@ -106,6 +109,10 @@ namespace MyCore.Controllers.Devices
{
return new BadRequestObjectResult(ex.Message) { StatusCode = 404 };
}
catch (ArgumentException ex)
{
return new BadRequestObjectResult(ex.Message) { StatusCode = 409 };
}
catch (Exception ex)
{
return new ObjectResult(ex.Message) { StatusCode = 500 };

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace MyCore.DTO.Common
{
public enum DeviceType // TO BE Continued
{
Sensor = 1,
Actuator,
Camera,
Light,
Sound,
Plug,
Thermostat,
Valve,
Gateway
}
}

View File

@ -11,16 +11,24 @@ namespace MyCore.DTO.MyControlPanel
{
public string Id { get; set; }
public string UserId { get; set; }
public string Name { get; set; }
public string Model { get; set; }
public DeviceType Type { get; set; }
public bool Status { get; set; }
public ConnectionStatus ConnectionStatus { get; set; }
public string LocationId { get; set; }
public string ProviderId { get; set; }
public string ProviderName { get; set; }
public LocationDTO Location { get; set; }
public DateTime LastStateDate { get; set; }
@ -34,10 +42,14 @@ namespace MyCore.DTO.MyControlPanel
{
public string Id { get; set; }
public string UserId { get; set; }
public string Name { get; set; }
public string Model { get; set; }
public DeviceType Type { get; set; }
public string FirmwareVersion { get; set; }
public int Port { get; set; }
@ -70,7 +82,9 @@ namespace MyCore.DTO.MyControlPanel
public string ProviderId { get; set; }
public List<string> Groups { get; set; }
public string ProviderName { get; set; }
public List<string> GroupIds { get; set; }
public Dictionary<string, object> Properties { get; set; }

View File

@ -19,6 +19,10 @@ namespace MyCore.Models.MyControlPanel.Database
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonElement("UserId")]
[BsonRequired]
public string UserId { get; set; }
[BsonElement("Name")]
[BsonRequired]
public string Name { get; set; }
@ -38,6 +42,9 @@ namespace MyCore.Models.MyControlPanel.Database
[BsonElement("Status")]
public bool Status { get; set; }
[BsonElement("Type")]
public DeviceType Type { get; set; }
[BsonElement("ConnectionStatus")]
public ConnectionStatus ConnectionStatus { get; set; }
@ -89,10 +96,13 @@ namespace MyCore.Models.MyControlPanel.Database
return new DeviceSummaryDTO()
{
Id = Id,
UserId = UserId,
Name = Name,
Model = Model,
Type = Type,
Status = Status,
ConnectionStatus = ConnectionStatus,
ProviderId = ProviderId,
LocationId = LocationId, // Check if correct way
// Location =
LastStateDate = LastStateDate,
@ -106,8 +116,10 @@ namespace MyCore.Models.MyControlPanel.Database
return new DeviceDetailDTO()
{
Id = Id,
UserId = UserId,
Name = Name,
Model = Model,
Type = Type,
Status = Status,
Port = Port,
FirmwareVersion = FirmwareVersion,
@ -122,7 +134,7 @@ namespace MyCore.Models.MyControlPanel.Database
IpAddress = IpAddress,
ServiceIdentification = ServiceIdentification,
ProviderId = ProviderId,
Groups = GroupIds,
GroupIds = GroupIds,
Properties = Properties,
SupportedOperations = SupportedOperations,
Battery = Battery,

View File

@ -45,6 +45,10 @@ namespace MyCore.Models.MyControlPanel.Database
{
Id = Id,
Name = Name,
UserId = UserId,
/*Username = Username,
Password = Password,
ApiKey = ApiKey,*/
Active = Active
};
}

View File

@ -16,7 +16,7 @@ namespace MyCore.Services.Devices
public class DeviceService
{
public static DeviceDetailDTO CreateOrUpdate(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, DeviceDetailDTO deviceDetailDTO, bool create)
public static DeviceDetailDTO CreateOrUpdate(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, DeviceDetailDTO deviceDetailDTO, bool create)
{
Device device;
if (create)
@ -26,12 +26,14 @@ namespace MyCore.Services.Devices
device = _DeviceDatabaseService.GetById(deviceDetailDTO.Id);
}
if (_DeviceDatabaseService.IsAlreadyHere(deviceDetailDTO.IpAddress, deviceDetailDTO.Port) && create)
if (_DeviceDatabaseService.IsAlreadyHere(userId, deviceDetailDTO.ServiceIdentification, deviceDetailDTO.Model) && create)
{
return null;
}
device.UserId = userId;
device.Name = deviceDetailDTO.Name;
if (_ProviderDatabaseService.IsExist(deviceDetailDTO.ProviderId))
device.ProviderId = deviceDetailDTO.ProviderId;
else
@ -44,14 +46,15 @@ namespace MyCore.Services.Devices
device.Port = deviceDetailDTO.Port;
device.Model = deviceDetailDTO.Model;
device.Type = deviceDetailDTO.Type;
device.FirmwareVersion = deviceDetailDTO.FirmwareVersion;
device.Status = deviceDetailDTO.Status;
if (create)
device.ConnectionStatus = ConnectionStatus.Unknown;
else
device.ConnectionStatus = deviceDetailDTO.ConnectionStatus;
device.Status = device.Status;
device.LocationId = device.LocationId;
device.Status = deviceDetailDTO.Status;
device.LocationId = deviceDetailDTO.LocationId;
device.CreatedDate = DateTime.Now;
device.UpdatedDate = DateTime.Now;
@ -60,11 +63,11 @@ namespace MyCore.Services.Devices
device.ServiceIdentification = deviceDetailDTO.ServiceIdentification;
device.Battery = deviceDetailDTO.Battery;
device.BatteryStatus = deviceDetailDTO.BatteryStatus;
device.GroupIds = device.GroupIds;
device.GroupIds = deviceDetailDTO.GroupIds;
// Todo structure Properties
device.Properties = device.Properties;
device.Properties = deviceDetailDTO.Properties;
// Todo structure SupportedOperations
device.SupportedOperations = device.SupportedOperations;
device.SupportedOperations = deviceDetailDTO.SupportedOperations;
if (create)
return _DeviceDatabaseService.Create(device).ToDTO();
@ -72,7 +75,7 @@ namespace MyCore.Services.Devices
return _DeviceDatabaseService.Update(device.Id, device).ToDTO();
}
public async static Task<List<DeviceDetailDTO>> CreateFromProvider(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, Provider provider)
public async static Task<List<DeviceDetailDTO>> CreateFromProvider(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, Provider provider)
{
if (!ProviderService.IsProviderSupported(provider.Name))
throw new KeyNotFoundException("Provider is not yet supported");
@ -84,15 +87,15 @@ namespace MyCore.Services.Devices
{
case "Arlo":
List<Models.Arlo.ArloDevice> arloDevices = new ArloService(provider.Username, provider.Password).GetAllDevices();
createdDevice = CreateArloDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, arloDevices, provider);
createdDevice = CreateArloDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, arloDevices, provider);
break;
case "Meross":
List<Models.Meross.MerossDevice> merossDevices = new MerossService(provider.Username, provider.Password).GetMerossDevices();
createdDevice = CreateMerossDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, merossDevices, provider);
createdDevice = CreateMerossDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, merossDevices, provider);
break;
case "Yeelight":
List<YeelightAPI.Device> yeelightDevices = await new YeelightService().GetDevices();
createdDevice = CreateYeelightDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, yeelightDevices, provider);
createdDevice = CreateYeelightDevices(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, yeelightDevices, provider);
break;
}
}
@ -108,7 +111,7 @@ namespace MyCore.Services.Devices
return createdDevice;
}
public static List<DeviceDetailDTO> CreateArloDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, List<Models.Arlo.ArloDevice> arloDevices, Provider provider)
public static List<DeviceDetailDTO> CreateArloDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, List<Models.Arlo.ArloDevice> arloDevices, Provider provider)
{
List<DeviceDetailDTO> createdArloDevices = new List<DeviceDetailDTO>();
@ -116,41 +119,49 @@ namespace MyCore.Services.Devices
{
DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO();
deviceDetailDTO.Name = arlo.deviceName;
deviceDetailDTO.IpAddress = arlo.deviceId; // TO CHECK
deviceDetailDTO.ServiceIdentification = arlo.deviceId;
deviceDetailDTO.ProviderId = provider.Id;
if (arlo.connectivity != null)
{
deviceDetailDTO.ConnectionStatus = arlo.connectivity.connected ? ConnectionStatus.Connected : ConnectionStatus.Unknown;
deviceDetailDTO.Status = arlo.connectivity.connected ? true : false; // TODO STATE
deviceDetailDTO.Model = arlo.deviceType;
//deviceDetailDTO.Port = arlo.; // TO CHECK
deviceDetailDTO.FirmwareVersion = arlo.interfaceVersion; // TODO
/*Dictionary<string, object> properties = new Dictionary<string, object>();
foreach (var property in arlo.properties)
{
properties.Add(property.Key, property.Value);
}*/ // TODO
// deviceDetailDTO.Properties = properties;
}
else
deviceDetailDTO.ConnectionStatus = ConnectionStatus.Unknown;
// TODO !
List<string> supportedOperationsDTO = new List<string>();
supportedOperationsDTO.Add(arlo.lastImageUploaded.GetType().Name + " : " + arlo.lastImageUploaded);
supportedOperationsDTO.Add(arlo.presignedLastImageUrl.GetType().Name + " : " + arlo.presignedLastImageUrl);
supportedOperationsDTO.Add(arlo.presignedFullFrameSnapshotUrl.GetType().Name + " : " + arlo.presignedFullFrameSnapshotUrl);
supportedOperationsDTO.Add(arlo.presignedSnapshotUrl.GetType().Name + " : " + arlo.presignedSnapshotUrl);
deviceDetailDTO.SupportedOperations = supportedOperationsDTO;
deviceDetailDTO.Model = arlo.modelId;
deviceDetailDTO.FirmwareVersion = arlo.interfaceVersion; // TODO
switch (arlo.deviceType)
{
case "camera":
deviceDetailDTO.Type = DeviceType.Camera;
Dictionary<string, object> properties = new Dictionary<string, object>();
properties.Add("lastImageUploaded", arlo.lastImageUploaded);
properties.Add("presignedLastImageUrl", arlo.presignedLastImageUrl);
properties.Add("presignedFullFrameSnapshotUrl", arlo.presignedFullFrameSnapshotUrl);
properties.Add("presignedSnapshotUrl", arlo.presignedSnapshotUrl);
deviceDetailDTO.Properties = properties;
break;
case "siren":
deviceDetailDTO.Type = DeviceType.Sound;
break;
case "basestation":
deviceDetailDTO.Type = DeviceType.Gateway;
break;
}
deviceDetailDTO.MeansOfCommunications = new List<MeansOfCommunication>();
deviceDetailDTO.MeansOfCommunications.Add(MeansOfCommunication.Wifi); // TO CHECK
deviceDetailDTO.MeansOfCommunications.Add(MeansOfCommunication.Wifi); // To check
deviceDetailDTO.CreatedDate = DateTime.Now;
deviceDetailDTO.UpdatedDate = DateTime.Now;
createdArloDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, deviceDetailDTO, true));
createdArloDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, deviceDetailDTO, true));
}
return createdArloDevices;
}
public static List<DeviceDetailDTO> CreateMerossDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, List<Models.Meross.MerossDevice> merossDevices, Provider provider)
public static List<DeviceDetailDTO> CreateMerossDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, List<Models.Meross.MerossDevice> merossDevices, Provider provider)
{
List<DeviceDetailDTO> createdMerossDevices = new List<DeviceDetailDTO>();
@ -158,12 +169,26 @@ namespace MyCore.Services.Devices
{
DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO();
deviceDetailDTO.Name = meross.devName;
deviceDetailDTO.IpAddress = meross.uuid; // TO CHECK
deviceDetailDTO.ServiceIdentification = meross.uuid;
deviceDetailDTO.ProviderId = provider.Id;
deviceDetailDTO.ConnectionStatus = meross.onlineStatus == 1 ? ConnectionStatus.Connected : ConnectionStatus.Disconnected;
// deviceDetailDTO.Status = meross. ? true : false; // TODO STATE
deviceDetailDTO.Model = meross.deviceType;
switch (deviceDetailDTO.Model) // TODO
{
case "mss425f":
deviceDetailDTO.Type = DeviceType.Plug;
break;
case "mss310":
deviceDetailDTO.Type = DeviceType.Actuator;
break;
case "msh300":
deviceDetailDTO.Type = DeviceType.Gateway;
break;
default:
deviceDetailDTO.Type = DeviceType.Actuator;
break;
}
//deviceDetailDTO.Port = arlo.; // TO CHECK
deviceDetailDTO.FirmwareVersion = meross.firmwareVersion; // TODO
/*Dictionary<string, object> properties = new Dictionary<string, object>();
@ -177,6 +202,7 @@ namespace MyCore.Services.Devices
Dictionary<string, object> properties = new Dictionary<string, object>();
foreach (var property in meross.channels)
{
if (property.type != null)
properties.Add(property.devName, property.type);
}
// deviceDetailDTO.SupportedOperations = supportedOperationsDTO; TODO
@ -185,13 +211,13 @@ namespace MyCore.Services.Devices
deviceDetailDTO.MeansOfCommunications.Add(MeansOfCommunication.Wifi); // TO CHECK
deviceDetailDTO.CreatedDate = DateTime.Now;
deviceDetailDTO.UpdatedDate = DateTime.Now;
createdMerossDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, deviceDetailDTO, true));
createdMerossDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, deviceDetailDTO, true));
}
return createdMerossDevices;
}
public static List<DeviceDetailDTO> CreateYeelightDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, List<YeelightAPI.Device> yeelightDevices, Provider provider)
public static List<DeviceDetailDTO> CreateYeelightDevices(DeviceDatabaseService _DeviceDatabaseService, ProviderDatabaseService _ProviderDatabaseService, LocationDatabaseService _LocationDatabaseService, string userId, List<YeelightAPI.Device> yeelightDevices, Provider provider)
{
List<DeviceDetailDTO> createdYeelightDevices = new List<DeviceDetailDTO>();
@ -200,10 +226,12 @@ namespace MyCore.Services.Devices
DeviceDetailDTO deviceDetailDTO = new DeviceDetailDTO();
deviceDetailDTO.Name = light.Name;
deviceDetailDTO.IpAddress = light.Hostname;
deviceDetailDTO.ServiceIdentification = light.Id;
deviceDetailDTO.ProviderId = provider.Id;
deviceDetailDTO.ConnectionStatus = ConnectionStatus.Connected;
deviceDetailDTO.Status = false;
deviceDetailDTO.Model = light.Model.ToString();
deviceDetailDTO.Type = DeviceType.Light; // TO CHECK
deviceDetailDTO.Port = light.Port;
deviceDetailDTO.FirmwareVersion = light.FirmwareVersion;
Dictionary<string, object> properties = new Dictionary<string, object>();
@ -222,7 +250,7 @@ namespace MyCore.Services.Devices
deviceDetailDTO.MeansOfCommunications.Add(MeansOfCommunication.Wifi);
deviceDetailDTO.CreatedDate = DateTime.Now;
deviceDetailDTO.UpdatedDate = DateTime.Now;
createdYeelightDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, deviceDetailDTO, true));
createdYeelightDevices.Add(CreateOrUpdate(_DeviceDatabaseService, _ProviderDatabaseService, _LocationDatabaseService, userId, deviceDetailDTO, true));
}
return createdYeelightDevices;

View File

@ -28,7 +28,7 @@ namespace MyCore.Services
private string _logUrl = $"{_merossUrl}/v1/log/user";
private string _devList = $"{_merossUrl}/v1/Device/devList";
private string username = "thomas.fransolet@hotmail.be";
private static string username = "thomas.fransolet@hotmail.be";
private static string password = "Coconuts07";
private static ResultToken resultToken;

View File

@ -20,9 +20,9 @@ namespace MyCore.Services.MyControlPanel
var database = client.GetDatabase("MyCoreDb");
_Devices = database.GetCollection<Device>("Devices");
}
public List<Device> GetAll()
public List<Device> GetAll(string userId)
{
return _Devices.Find(d => true).ToList();
return _Devices.Find(d => d.UserId == userId).ToList();
}
public Device GetById(string id)
@ -35,9 +35,9 @@ namespace MyCore.Services.MyControlPanel
return _Devices.Find<Device>(d => d.Id == id).FirstOrDefault() != null ? true : false;
}
public bool IsAlreadyHere(string ipAddress, int port)
public bool IsAlreadyHere(string userId, string serviceIdentification, string model)
{
return _Devices.Find<Device>(d => d.IpAddress == ipAddress && d.Port == port).FirstOrDefault() != null ? true : false;
return _Devices.Find<Device>(d => d.UserId == userId && d.ServiceIdentification == serviceIdentification && d.Model == model).FirstOrDefault() != null ? true : false;
}
public Device Create(Device device)
@ -56,5 +56,10 @@ namespace MyCore.Services.MyControlPanel
{
_Devices.DeleteOne(device => device.Id == id);
}
public void RemoveForUser(string userId)
{
_Devices.DeleteMany(device => device.UserId == userId);
}
}
}

View File

@ -29,6 +29,11 @@ namespace MyCore.Services.MyControlPanel
return _Providers.Find<Provider>(p => p.Id == id && p.UserId == userId).FirstOrDefault();
}
public bool AlreadyExistForUser(string userId, string name)
{
return _Providers.Find<Provider>(p => p.UserId == userId && p.Name == name).FirstOrDefault() != null ? true : false; ;
}
public Provider GetByName(string name)
{
return _Providers.Find<Provider>(p => p.Name == name).FirstOrDefault();