using HospitalContracts.BindingModels; using HospitalContracts.ViewModels; using HospitalDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HospitalDatabaseImplement.Models { public class Patient : IPatientModel { public int Id { get; private set; } public string Surname { get; private set; } = string.Empty; [Required] public string Name { get; private set; } = string.Empty; public string Patronymic { get; private set; } = string.Empty; [Required] public DateTime BirthDate { get; private set; } public int TreatmentId { get; private set; } public virtual Treatment? Treatment { get; set; } public static Patient? Create(PatientBindingModel model) { if (model == null) { return null; } return new Patient() { Id = model.Id, Surname = model.Surname, Name = model.Name, Patronymic = model.Patronymic, BirthDate = model.BirthDate, TreatmentId = model.TreatmentId }; } public static Patient Create(PatientViewModel model) { return new Patient { Id = model.Id, Surname = model.Surname, Name = model.Name, Patronymic = model.Patronymic, BirthDate = model.BirthDate, TreatmentId = model.TreatmentId }; } public void Update(PatientBindingModel model) { if (model == null) { return; } Surname = model.Surname; Name = model.Name; Patronymic = model.Patronymic; BirthDate = model.BirthDate; TreatmentId = model.TreatmentId; } public PatientViewModel GetViewModel => new() { Id = Id, Surname = Surname, Name = Name, Patronymic = Patronymic, BirthDate = BirthDate, TreatmentId = TreatmentId, TreatmentName = Treatment?.Name }; } }