using CarServiceContracts.BindingModels; using CarServiceContracts.Models; using CarServiceContracts.ViewModels; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace CarServiceDatabase.Models { public class RepairRequest : IRepairRequestModel { public int Id { get; private set; } [Required] public DateTime DateCreated { get; private set; } = DateTime.Now; [Required] public int VehicleId { get; private set; } /// /// Работы в заявке /// [ForeignKey("RepairRequestId")] public virtual List WorksInRequest { get; set; } = new(); /// /// Затраты на ремонт /// [ForeignKey("RepairRequestId")] public virtual List ItemsForRepair { get; set; } = new(); public static RepairRequest? Create(RepairRequestBindingModel? model) { if (model == null) { return null; } return new() { Id = model.Id, DateCreated = model.DateCreated, VehicleId = model.VehicleId }; } public static RepairRequest Create(RepairRequestViewModel model) { return new() { Id = model.Id, DateCreated = model.DateCreated, VehicleId = model.VehicleId }; } public void Update(RepairRequestBindingModel? model) { if (model == null) { return; } Id = model.Id; DateCreated = model.DateCreated; VehicleId = model.VehicleId; } public RepairRequestViewModel GetViewModel => new() { Id = Id, DateCreated = DateCreated, VehicleId = VehicleId }; } }