PIbd-23_Elatomtsev_L.K._SUB.../DeviceDatabaseImplement/Models/Service.cs
2024-05-20 05:17:39 +04:00

53 lines
1.6 KiB
C#

using DeviceDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using DeviceContracts.BindingModels;
using DeviceContracts.ViewModels;
namespace DeviceDatabaseImplement.Models
{
public class Service : IServiceModel
{
public int Id { get; set; }
[Required]
public string Description { get; set; } = string.Empty;
[Required]
public DateOnly StartDate { get; set; }
public DateOnly? EndDate { get; set; }
[Required]
public int DeviceId { get; set; }
public ICollection<Service> Services { get; set; }
= new List<Service>();
public static Service? Create(ServiceBindingModel model)
{
if (model == null)
return null;
return new Service
{
Id = model.Id,
Description = model.Description,
StartDate = model.StartDate,
EndDate = model.EndDate,
DeviceId = model.DeviceId,
};
}
public void Update(ServiceBindingModel model)
{
if (model == null)
return;
Id = model.Id;
Description = model.Description;
StartDate = model.StartDate;
EndDate = model.EndDate;
DeviceId = model.DeviceId;
}
public ServiceViewModel GetViewModel => new()
{
Id = Id,
Description = Description,
StartDate = StartDate,
EndDate = EndDate,
DeviceId = DeviceId,
};
}
}