using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using VeterinaryContracts.BindingModels; using VeterinaryContracts.ViewModels; using VeterinaryDataModels.Models; namespace VeterinaryDatabaseImplement.Models { public class Owner : IOwnerModel { public int Id { get; private set; } [Required] public string OwnerFIO { get; private set; } = string.Empty; [Required] public string Login { get; set; } = string.Empty; [Required] public string Password { get; set; } = string.Empty; [ForeignKey("OwnerId")] public virtual List Pets { get; set; } = new(); [ForeignKey("OwnerId")] public virtual List Visits { get; set; } = new(); [ForeignKey("OwnerId")] public virtual List Purchases { get; set; } = new(); public static Owner? Create(OwnerBindingModel model) { if (model == null) { return null; } return new Owner() { Id = model.Id, OwnerFIO = model.OwnerFIO, Login = model.Login, Password = model.Password }; } public static Owner Create(OwnerViewModel model) { return new Owner() { Id = model.Id, OwnerFIO = model.OwnerFIO, Login = model.Login, Password = model.Password }; } public void Update(OwnerBindingModel model) { if (model == null) { return; } OwnerFIO = model.OwnerFIO; Login = model.Login; Password = model.Password; } public OwnerViewModel GetViewModel => new() { Id = Id, OwnerFIO = OwnerFIO, Login = Login, Password = Password }; } }