66 lines
2.2 KiB
C#
66 lines
2.2 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; } = string.Empty;
|
|
public DateOnly? ProductionDate { get; set; }
|
|
public int? WarrantyPeriod { get; set; }
|
|
[Required]
|
|
public bool Condition { get; set; }
|
|
[Required]
|
|
public int KindId { get; set; }
|
|
public int? KitId { get; set; }
|
|
public virtual Kind Kind { get; set; } = new();
|
|
public virtual Kit Kit { get; set; } = new();
|
|
public static Device? Create(DeviceBindingModel model)
|
|
{
|
|
if (model == null)
|
|
return null;
|
|
return new Device
|
|
{
|
|
Id = model.Id,
|
|
Model = model.Model,
|
|
SerialNumber = model.SerialNumber ?? string.Empty,
|
|
ProductionDate = model.ProductionDate,
|
|
WarrantyPeriod = model.WarrantyPeriod ?? 0,
|
|
Condition = model.Condition,
|
|
KindId = model.KindId,
|
|
KitId = model.KitId ?? 0,
|
|
};
|
|
}
|
|
public void Update(DeviceBindingModel model)
|
|
{
|
|
if (model == null)
|
|
return;
|
|
Id = model.Id;
|
|
Model = model.Model;
|
|
SerialNumber = model.SerialNumber ?? string.Empty;
|
|
ProductionDate = model.ProductionDate;
|
|
WarrantyPeriod = model.WarrantyPeriod ?? 0;
|
|
Condition = model.Condition;
|
|
KindId = model.KindId;
|
|
KitId = model.KitId ?? 0;
|
|
}
|
|
public DeviceViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Model = Model,
|
|
SerialNumber = SerialNumber ?? string.Empty,
|
|
ProductionDate = ProductionDate,
|
|
WarrantyPeriod = WarrantyPeriod ?? 0,
|
|
Condition = Condition,
|
|
KindId = KindId,
|
|
KitId = KitId ?? 0,
|
|
};
|
|
}
|
|
} |