using LawCompanyDataModels.Models; using LawCompanyContracts.BindingModels; using LawCompanyContracts.ViewModels; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; namespace LawCompanyDatabaseImplement.Models { public class Client : IClientModel { public int Id { get; private set; } [Required] public string FIO { get; private set; } = string.Empty; [Required] public string Email { get; private set; } = string.Empty; [Required] public string Phone { get; private set; } = string.Empty; [ForeignKey("ClientId")] public virtual List CaseClients { get; set; } = new(); [ForeignKey("ClientId")] public virtual List ClientVisits { get; set; } = new(); public static Client? Create(ClientBindingModel? model) { if (model == null) { return null; } return new Client() { Id = model.Id, FIO = model.FIO, Email = model.Email, Phone = model.Phone, }; } public static Client Create(ClientViewModel model) { return new Client { Id = model.Id, FIO = model.FIO, Email = model.Email, Phone = model.Phone, }; } public void Update(ClientBindingModel? model) { if (model == null) { return; } FIO = model.FIO; Email = model.Email; Phone = model.Phone; } public ClientViewModel GetViewModel => new() { Id = Id, FIO = FIO, Email = Email, Phone = Phone, }; } }