using CarServiceContracts.BindingModels; using CarServiceContracts.Models; using CarServiceContracts.ViewModels; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace CarServiceDatabase.Models { public class Customer : ICustomerModel { public int Id { get; private set; } [Required] public string Login { get; private set; } = string.Empty; [Required] public string Password { get; private set; } = string.Empty; [Required] public string Name { get; private set; } = string.Empty; [Required] public string Surname { get; private set; } = string.Empty; /// /// Транспортные средства /// [ForeignKey("CustomerId")] public virtual List Vehicles { get; set; } = new(); public static Customer? Create(CustomerBindingModel? model) { if (model == null) { return null; } return new() { Login = model.Login, Password = model.Password, Name = model.Name, Surname = model.Surname }; } public void Update(CustomerBindingModel? model) { if (model == null) { return; } Login = model.Login; Password = model.Password; Name = model.Name; Surname = model.Surname; } public CustomerViewModel GetViewModel => new() { Id = Id, Login = Login, Password = Password, Name = Name, Surname = Surname }; } }