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