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