using CarServiceContracts.BindingModels; using CarServiceContracts.Models; using CarServiceContracts.ViewModels; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace CarServiceDatabase.Models { public class Vehicle : IVehicleModel { public int Id { get; private set; } [Required] public string Name { get; private set; } = string.Empty; public string? Plate { get; private set; } public string? VIN { get; private set; } [Required] public int CustomerId { get; private set; } /// /// Заявки на ремонт /// [ForeignKey("VehicleId")] public virtual List RepairRequests { get; set; } = new(); public virtual Customer Customer { get; set; } = new(); public static Vehicle? Create(VehicleBindingModel? model) { if (model == null) { return null; } return new() { Id = model.Id, Name = model.Name, Plate = model.Plate, VIN = model.VIN, CustomerId = model.CustomerId }; } public static Vehicle Create(VehicleViewModel model) { return new() { Id = model.Id, Name = model.Name, Plate = model.Plate, VIN = model.VIN, CustomerId = model.CustomerId }; } public void Update(VehicleBindingModel? model) { if (model == null) { return; } Id = model.Id; Name = model.Name; Plate = model.Plate; VIN = model.VIN; CustomerId = model.CustomerId; } public VehicleViewModel GetViewModel => new() { Id = Id, Name = Name, Plate = Plate, VIN = VIN, CustomerId = CustomerId }; } }