mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using MyCore.DTO.Common;
|
|
using MyCore.DTO.MyControlPanel;
|
|
using MyCore.Models.MyControlPanel;
|
|
using MyCore.Services.MyControlPanel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MyCore.Services.Devices
|
|
{
|
|
public class DeviceService
|
|
{
|
|
private static DeviceDatabaseService _DeviceDatabaseService;
|
|
private static ProviderDatabaseService _ProviderDatabaseService;
|
|
private static LocationDatabaseService _LocationDatabaseService;
|
|
|
|
public static DeviceDetailDTO CreateOrUpdate(DeviceDetailDTO deviceDetailDTO, bool create)
|
|
{
|
|
Device device;
|
|
if (create)
|
|
device = new Device();
|
|
else
|
|
{
|
|
device = _DeviceDatabaseService.GetById(deviceDetailDTO.Id);
|
|
}
|
|
|
|
device.Name = deviceDetailDTO.Name;
|
|
if (_ProviderDatabaseService.IsExist(deviceDetailDTO.ProviderId))
|
|
device.ProviderId = deviceDetailDTO.ProviderId;
|
|
else
|
|
throw new KeyNotFoundException("Provider does not exist");
|
|
|
|
if (_LocationDatabaseService.IsExist(deviceDetailDTO.LocationId))
|
|
device.LocationId = deviceDetailDTO.LocationId;
|
|
else
|
|
throw new KeyNotFoundException("Location does not exist");
|
|
|
|
device.ConnectionStatus = ConnectionStatus.Unknown;
|
|
device.CreatedDate = DateTime.Now;
|
|
device.UpdatedDate = DateTime.Now;
|
|
|
|
device.MeansOfCommunications = deviceDetailDTO.MeansOfCommunications;
|
|
device.IpAddress = deviceDetailDTO.IpAddress;
|
|
device.Battery = deviceDetailDTO.Battery;
|
|
device.BatteryStatus = deviceDetailDTO.BatteryStatus;
|
|
device.GroupIds = device.GroupIds;
|
|
// Todo structure informations
|
|
device.Information = device.Information;
|
|
|
|
if (create)
|
|
return _DeviceDatabaseService.Create(device).ToDTO();
|
|
else
|
|
return _DeviceDatabaseService.Update(device.Id, device).ToDTO();
|
|
}
|
|
}
|
|
}
|