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

45 lines
1.4 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 Kit : IKitModel
{
public int Id { get; set; }
[Required]
public string Title { get; set; } = string.Empty;
public int? CabinetId { get; set; }
public virtual Cabinet Cabinet { get; set; } = new();
public ICollection<Device> Devices { get; set; } = new List<Device>();
public virtual ICollection<Ownership> Ownership { get; set; }
= new List<Ownership>();
public static Kit? Create(KitBindingModel model)
{
if (model == null)
return null;
return new Kit
{
Id = model.Id,
Title = model.Title,
CabinetId = model.CabinetId ?? 0
};
}
public void Update(KitBindingModel model)
{
if (model == null)
return;
Id = model.Id;
Title = model.Title;
CabinetId = model.CabinetId ?? 0;
}
public KitViewModel GetViewModel => new()
{
Id = Id,
Title = Title,
CabinetId = CabinetId ?? 0,
};
}
}