using CarServiceContracts.BindingModels; using CarServiceContracts.Models; using CarServiceContracts.ViewModels; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace CarServiceDatabase.Models { public class WorkInRequest : IWorkInRequestModel { public int Id { get; private set; } [Required] public int Count { get; private set; } [Required, Column(TypeName = "decimal (10,2)")] public decimal Cost { get; private set; } [Required] public int RepairRequestId { get; private set; } [Required] public int WorkId { get; private set; } /// /// Оплаты за ремонт /// [ForeignKey("WorkInRequestId")] public virtual List WorkPayments { get; set; } = new(); public virtual RepairRequest RepairRequest { get; set; } = new(); public virtual Work Work { get; set; } = new(); public static WorkInRequest? Create(WorkInRequestBindingModel? model) { if (model == null) { return null; } return new() { Id = model.Id, Count = model.Count, Cost = model.Cost, RepairRequestId = model.RepairRequestId, WorkId = model.WorkId }; } public static WorkInRequest Create(WorkInRequestViewModel model) { return new() { Id = model.Id, Count = model.Count, Cost = model.Cost, RepairRequestId = model.RepairRequestId, WorkId = model.WorkId }; } public void Update(WorkInRequestBindingModel? model) { if (model == null) { return; } Id = model.Id; Count = model.Count; Cost = model.Cost; RepairRequestId = model.RepairRequestId; WorkId = model.WorkId; } public WorkInRequestViewModel GetViewModel => new() { Id = Id, Count = Count, Cost = Cost, RepairRequestId = RepairRequestId, WorkId = WorkId }; } }