132 lines
4.4 KiB
C#
132 lines
4.4 KiB
C#
using ManagerService.DTOs;
|
|
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace ManagerService.Data
|
|
{
|
|
/// <summary>
|
|
/// Device Information (Tablet)
|
|
/// </summary>
|
|
public class Device
|
|
{
|
|
[Key]
|
|
[Required]
|
|
/*[BsonId]
|
|
[BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]*/
|
|
public string Id { get; set; }
|
|
|
|
//[BsonElement("Identifier")]
|
|
public string Identifier { get; set; }
|
|
|
|
//[BsonElement("Name")]
|
|
public string Name { get; set; }
|
|
|
|
/*[BsonElement("IpAddressWLAN")]
|
|
[BsonRequired]*/
|
|
//[Required]
|
|
public string IpAddressWLAN { get; set; }
|
|
|
|
//[BsonElement("IpAddressETH")]
|
|
//[BsonRequired]
|
|
//[Required]
|
|
public string IpAddressETH { get; set; }
|
|
|
|
//[BsonElement("Configuration")]
|
|
public Configuration Configuration { get; set; }
|
|
|
|
//[BsonElement("ConfigurationId")]
|
|
//[BsonRequired]
|
|
[Required]
|
|
[ForeignKey("ConfigurationId")]
|
|
public string ConfigurationId { get; set; }
|
|
|
|
//[BsonElement("Connected")]
|
|
//[BsonRequired]
|
|
[Required]
|
|
public bool Connected { get; set; }
|
|
|
|
//[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; }
|
|
|
|
//[BsonElement("LastBatteryLevel")]
|
|
public DateTime LastBatteryLevel { get; set; }
|
|
|
|
// ConnectionLevel wifi strength level
|
|
//[BsonElement("ConnectionLevel")]
|
|
public string ConnectionLevel { get; set; }
|
|
|
|
//[BsonElement("LastConnectionLevel")]
|
|
public DateTime LastConnectionLevel { get; set; }
|
|
|
|
/*[BsonElement("InstanceId")]
|
|
[BsonRequired]*/
|
|
[Required]
|
|
public string InstanceId { get; set; }
|
|
|
|
public DeviceDTO ToDTO()
|
|
{
|
|
return new DeviceDTO()
|
|
{
|
|
id = Id,
|
|
identifier = Identifier,
|
|
name = Name,
|
|
ipAddressWLAN = IpAddressWLAN,
|
|
ipAddressETH = IpAddressETH,
|
|
connected = Connected,
|
|
configuration = Configuration?.Label,
|
|
configurationId = ConfigurationId,
|
|
dateUpdate = DateUpdate,
|
|
dateCreation = DateCreation,
|
|
instanceId = InstanceId
|
|
};
|
|
}
|
|
|
|
public DeviceDetailDTO ToDetailDTO()
|
|
{
|
|
return new DeviceDetailDTO()
|
|
{
|
|
id = Id,
|
|
identifier = Identifier,
|
|
name = Name,
|
|
ipAddressWLAN = IpAddressWLAN,
|
|
ipAddressETH = IpAddressETH,
|
|
connected = Connected,
|
|
configuration = Configuration.Label,
|
|
configurationId = ConfigurationId,
|
|
connectionLevel = ConnectionLevel,
|
|
lastConnectionLevel = LastConnectionLevel,
|
|
batteryLevel = BatteryLevel,
|
|
lastBatteryLevel = LastBatteryLevel,
|
|
dateUpdate = DateUpdate,
|
|
dateCreation = DateCreation,
|
|
instanceId = InstanceId
|
|
};
|
|
}
|
|
|
|
public Device FromDTO(DeviceDetailDTO deviceDetailDTO)
|
|
{
|
|
Name = deviceDetailDTO.name;
|
|
DateCreation = deviceDetailDTO.dateCreation != null ? deviceDetailDTO.dateCreation.Value : DateTime.Now.ToUniversalTime();
|
|
Identifier = deviceDetailDTO.identifier;
|
|
IpAddressWLAN = deviceDetailDTO.ipAddressWLAN;
|
|
IpAddressETH = deviceDetailDTO.ipAddressETH;
|
|
Connected = deviceDetailDTO.connected;
|
|
ConfigurationId = deviceDetailDTO.configurationId;
|
|
ConnectionLevel = deviceDetailDTO.connectionLevel;
|
|
LastConnectionLevel = deviceDetailDTO.lastConnectionLevel;
|
|
BatteryLevel = deviceDetailDTO.batteryLevel;
|
|
LastBatteryLevel = deviceDetailDTO.lastBatteryLevel;
|
|
DateUpdate = deviceDetailDTO.dateUpdate != null ? deviceDetailDTO.dateUpdate.Value : DateTime.Now.ToUniversalTime();
|
|
InstanceId = deviceDetailDTO.instanceId;
|
|
return this;
|
|
}
|
|
}
|
|
} |