Add identifier, dateupdate + MapType to MapTypeApp
This commit is contained in:
parent
43e3ce2922
commit
0ee024e8ef
@ -7,6 +7,7 @@ namespace Manager.Interfaces.DTO
|
||||
public class DeviceDTO
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Identifier { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string IpAddressWLAN { get; set; }
|
||||
public string IpAddressETH { get; set; }
|
||||
@ -14,6 +15,7 @@ namespace Manager.Interfaces.DTO
|
||||
public string Configuration { get; set; }
|
||||
public bool Connected{ get; set; }
|
||||
public DateTime DateCreation{ get; set; }
|
||||
public DateTime DateUpdate { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceDetailDTO : DeviceDTO
|
||||
|
||||
@ -8,7 +8,7 @@ namespace Manager.Interfaces.DTO
|
||||
public class MapDTO
|
||||
{
|
||||
public int Zoom { get; set; } // Default = 18
|
||||
public MapType MapType { get; set; } // Default = Hybrid
|
||||
public MapTypeApp MapType { get; set; } // Default = Hybrid
|
||||
public List<GeoPointDTO> Points { get; set; }
|
||||
public string IconResourceId { get; set; }
|
||||
public string IconSource { get; set; } // url to resource id (local) or on internet
|
||||
@ -30,7 +30,7 @@ namespace Manager.Interfaces.DTO
|
||||
public string ImageSource { get; set; } // url to resource id (local) or on internet
|
||||
}
|
||||
|
||||
public enum MapType
|
||||
public enum MapTypeApp
|
||||
{
|
||||
none,
|
||||
normal,
|
||||
|
||||
@ -15,6 +15,9 @@ namespace Manager.Interfaces.Models
|
||||
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[BsonElement("Identifier")]
|
||||
public string Identifier { get; set; }
|
||||
|
||||
[BsonElement("Name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
@ -40,6 +43,9 @@ namespace Manager.Interfaces.Models
|
||||
[BsonElement("DateCreation")]
|
||||
public DateTime DateCreation { get; set; }
|
||||
|
||||
[BsonElement("DateUpdate")]
|
||||
public DateTime DateUpdate { get; set; }
|
||||
|
||||
// BatteryLevel in case of powered devices
|
||||
[BsonElement("BatteryLevel")]
|
||||
public string BatteryLevel { get; set; }
|
||||
@ -60,12 +66,14 @@ namespace Manager.Interfaces.Models
|
||||
return new DeviceDTO()
|
||||
{
|
||||
Id = Id,
|
||||
Identifier = Identifier,
|
||||
Name = Name,
|
||||
IpAddressWLAN = IpAddressWLAN,
|
||||
IpAddressETH = IpAddressETH,
|
||||
Connected = Connected,
|
||||
Configuration = Configuration,
|
||||
ConfigurationId = ConfigurationId,
|
||||
DateUpdate = DateUpdate,
|
||||
DateCreation = DateCreation
|
||||
};
|
||||
}
|
||||
@ -75,6 +83,7 @@ namespace Manager.Interfaces.Models
|
||||
return new DeviceDetailDTO()
|
||||
{
|
||||
Id = Id,
|
||||
Identifier = Identifier,
|
||||
Name = Name,
|
||||
IpAddressWLAN = IpAddressWLAN,
|
||||
IpAddressETH = IpAddressETH,
|
||||
@ -85,6 +94,7 @@ namespace Manager.Interfaces.Models
|
||||
LastConnectionLevel = LastConnectionLevel,
|
||||
BatteryLevel = BatteryLevel,
|
||||
LastBatteryLevel = LastBatteryLevel,
|
||||
DateUpdate = DateUpdate,
|
||||
DateCreation = DateCreation
|
||||
};
|
||||
}
|
||||
|
||||
@ -106,10 +106,19 @@ namespace ManagerService.Controllers
|
||||
if (configuration == null)
|
||||
throw new KeyNotFoundException("Configuration does not exist");
|
||||
|
||||
if (_deviceService.IsExistIpWLAN(newDevice.IpAddressWLAN) || _deviceService.IsExistIpETH(newDevice.IpAddressETH))
|
||||
throw new InvalidOperationException("Device with same ip already exist in system");
|
||||
|
||||
Device device = new Device();
|
||||
if (_deviceService.IsExistIdentifier(newDevice.Identifier))
|
||||
{
|
||||
// Update info
|
||||
device = _deviceService.GetByIdentifier(newDevice.Identifier);
|
||||
device.DateUpdate = DateTime.Now;
|
||||
}
|
||||
else {
|
||||
// Creation
|
||||
device.Identifier = newDevice.Identifier;
|
||||
device.DateCreation = DateTime.Now;
|
||||
}
|
||||
|
||||
device.Name = newDevice.Name;
|
||||
device.Configuration = configuration.Label;
|
||||
device.ConfigurationId = newDevice.ConfigurationId;
|
||||
@ -120,9 +129,8 @@ namespace ManagerService.Controllers
|
||||
device.LastConnectionLevel = newDevice.LastConnectionLevel;
|
||||
device.BatteryLevel = newDevice.BatteryLevel;
|
||||
device.LastBatteryLevel = newDevice.LastBatteryLevel;
|
||||
device.DateCreation = DateTime.Now;
|
||||
|
||||
Device deviceCreated = _deviceService.Create(device);
|
||||
Device deviceCreated = _deviceService.IsExistIdentifier(newDevice.Identifier) ? _deviceService.Update(device.Id, device) : _deviceService.Create(device);
|
||||
|
||||
return new OkObjectResult(deviceCreated.ToDTO());
|
||||
}
|
||||
@ -168,6 +176,7 @@ namespace ManagerService.Controllers
|
||||
|
||||
// Todo add some verification ?
|
||||
device.Name = updatedDevice.Name;
|
||||
device.Identifier = updatedDevice.Identifier;
|
||||
device.IpAddressWLAN = updatedDevice.IpAddressWLAN;
|
||||
device.IpAddressETH = updatedDevice.IpAddressETH;
|
||||
device.Connected = updatedDevice.Connected;
|
||||
|
||||
@ -275,7 +275,7 @@ namespace ManagerService.Controllers
|
||||
switch (newSection.Type) {
|
||||
case SectionType.Map:
|
||||
mapDTO = new MapDTO();
|
||||
mapDTO.MapType = MapType.hybrid;
|
||||
mapDTO.MapType = MapTypeApp.hybrid;
|
||||
mapDTO.Zoom = 18;
|
||||
|
||||
mapDTO.Points = new List<GeoPointDTO>() {
|
||||
|
||||
@ -34,6 +34,16 @@ namespace Manager.Services
|
||||
return _Devices.Find<Device>(d => d.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public Device GetByIdentifier(string identifier)
|
||||
{
|
||||
return _Devices.Find<Device>(d => d.Identifier == identifier).FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool IsExistIdentifier(string identifier)
|
||||
{
|
||||
return _Devices.Find<Device>(d => d.Identifier == identifier).FirstOrDefault() != null ? true : false;
|
||||
}
|
||||
|
||||
public bool IsExistIpWLAN(string ip)
|
||||
{
|
||||
return _Devices.Find<Device>(d => d.IpAddressWLAN == ip).FirstOrDefault() != null ? true : false;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user