103 lines
3.2 KiB
C#

using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MyCore.DTO.Common;
using MyCore.DTO.MyControlPanel;
using MyCore.Services.MyControlPanel;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MyCore.Models.MyControlPanel
{
/// <summary>
/// Group of devices
/// </summary>
public class Device
{
private LocationDatabaseService _LocationDatabaseService;
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonElement("Name")]
[BsonRequired]
public string Name { get; set; }
[BsonElement("ConnectionStatus")]
public ConnectionStatus ConnectionStatus { get; set; }
[BsonElement("LocationId")]
[BsonRequired]
public string LocationId { get; set; }
[BsonElement("MeansOfCommunications")]
public List<MeansOfCommunication> MeansOfCommunications { get; set; }
[BsonElement("CreatedDate")]
public DateTime CreatedDate { get; set; }
[BsonElement("UpdatedDate")]
public DateTime UpdatedDate { get; set; }
[BsonElement("LastMessage")]
public string LastMessage { get; set; } // TODO UNIFORMISATION ?
[BsonElement("LastMessageDate")]
public DateTime LastMessageDate { get; set; }
[BsonElement("IpAddress")]
public string IpAddress { get; set; }
[BsonElement("Battery")]
public bool Battery { get; set; }
[BsonElement("BatteryStatus")]
public int BatteryStatus { get; set; }
[BsonElement("ProviderId")]
[BsonRequired]
public string ProviderId { get; set; }
[BsonElement("GroupIds")]
public List<string> GroupIds { get; set; }
[BsonElement("Informations")]
public List<Information> Information { get; set; }
public DeviceSummaryDTO ToSummaryDTO()
{
return new DeviceSummaryDTO()
{
Id = Id,
Name = Name,
ConnectionStatus = ConnectionStatus,
Location = _LocationDatabaseService.GetById(LocationId).ToDTO(), // Check if correct way
Battery = Battery,
BatteryStatus = BatteryStatus
};
}
public DeviceDetailDTO ToDTO()
{
return new DeviceDetailDTO()
{
Id = Id,
Name = Name,
ConnectionStatus = ConnectionStatus,
Location = _LocationDatabaseService.GetById(LocationId).ToDTO(), // Check if correct way
MeansOfCommunications = MeansOfCommunications,
CreatedDate = CreatedDate,
UpdatedDate = UpdatedDate,
LastMessage = LastMessage,
LastMessageDate = LastMessageDate,
IpAddress = IpAddress,
//Provider = Provider.ToDTO(device.Provider),
//Groups = device.Groups.Select(i => i.ToDTO(i)).ToList(),
//Informations = device.Informations.Select(i => i.ToDTO(i)).ToList(),
Battery = Battery,
BatteryStatus = BatteryStatus
};
}
}
}