66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using DeviceDataModels.Models;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using DeviceContracts.BindingModels;
|
|
using DeviceContracts.ViewModels;
|
|
using System.ComponentModel;
|
|
|
|
namespace DeviceDatabaseImplement.Models
|
|
{
|
|
public class Device : IDeviceModel
|
|
{
|
|
public int Id { get; set; }
|
|
[Required]
|
|
public string Model { get; set; } = string.Empty;
|
|
public string? SerialNumber { get; set; }
|
|
public DateOnly? ProductionDate { get; set; }
|
|
public int? WarrantyPeriod { get; set; }
|
|
public bool Condition { get; set; }
|
|
[ForeignKey("Kind")]
|
|
public int KindId { get; set; }
|
|
public Kind? Kind { get; set; }
|
|
[ForeignKey("Kit")]
|
|
public int? KitId { get; set; }
|
|
public Kit? Kit { get; set; }
|
|
public static Device? Create(DeviceBindingModel model)
|
|
{
|
|
if (model == null)
|
|
return null;
|
|
return new Device
|
|
{
|
|
Id = model.Id,
|
|
Model = model.Model,
|
|
SerialNumber = model.SerialNumber,
|
|
ProductionDate = model.ProductionDate,
|
|
WarrantyPeriod = model.WarrantyPeriod,
|
|
Condition = model.Condition,
|
|
KindId = model.KindId,
|
|
KitId = model.KitId,
|
|
};
|
|
}
|
|
public void Update(DeviceBindingModel model)
|
|
{
|
|
if (model == null)
|
|
return;
|
|
Id = model.Id;
|
|
Model = model.Model;
|
|
SerialNumber = model.SerialNumber;
|
|
ProductionDate = model.ProductionDate;
|
|
WarrantyPeriod = model.WarrantyPeriod;
|
|
Condition = model.Condition;
|
|
KindId = model.KindId;
|
|
KitId = model.KitId;
|
|
}
|
|
public DeviceViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Model = Model,
|
|
SerialNumber = SerialNumber,
|
|
ProductionDate = ProductionDate,
|
|
WarrantyPeriod = WarrantyPeriod,
|
|
Condition = Condition,
|
|
KindId = KindId,
|
|
KitId = KitId,
|
|
};
|
|
}
|
|
} |