using CarServiceContracts.BindingModels; using CarServiceContracts.Models; using CarServiceContracts.ViewModels; using System.ComponentModel.DataAnnotations; namespace CarServiceDatabase.Models { public class ItemForRepair : IItemForRepairModel { public int Id { get; private set; } [Required] public int Count { get; private set; } [Required] public int ItemId { get; private set; } [Required] public int RepairRequestId { get; private set; } public static ItemForRepair? Create(ItemForRepairBindingModel? model) { if (model == null) { return null; } return new() { Id = model.Id, Count = model.Count, ItemId = model.ItemId, RepairRequestId = model.RepairRequestId }; } public static ItemForRepair Create(ItemForRepairViewModel model) { return new() { Id = model.Id, Count = model.Count, ItemId = model.ItemId, RepairRequestId = model.RepairRequestId }; } public void Update(ItemForRepairBindingModel? model) { if (model == null) { return; } Id = model.Id; Count = model.Count; ItemId = model.ItemId; RepairRequestId = model.RepairRequestId; } public ItemForRepairViewModel GetViewModel => new() { Id = Id, Count = Count, ItemId = ItemId, RepairRequestId = RepairRequestId }; } }