using PolyclinicContracts.BindingModels; using PolyclinicContracts.ViewModels; using PolyclinicDataModels.Models; using SecuritySystemDatabaseImplement; using System.ComponentModel.DataAnnotations; namespace PolyclinicDatabaseImplement.Models { public class Medicament : IMedicamentModel { public int Id { get; set; } [Required] public string Name { get; set; } = string.Empty; public string? Comment { get; set; } = string.Empty; public int? ProcedureId { get; set; } public int? SymptomId { get; set; } public virtual Symptom? Symptom { get; set; } public virtual Procedure? Procedure { get; set; } public static Medicament? Create(MedicamentBindingModel bindingModel) { return new Medicament() { Id = bindingModel.Id, Name = bindingModel.Name, Comment = bindingModel.Comment, ProcedureId = bindingModel.ProcedureId, SymptomId = bindingModel.SymptomId }; } public void Update(MedicamentBindingModel bindingModel) { Name = bindingModel.Name; Comment = bindingModel.Comment; ProcedureId = bindingModel.ProcedureId; SymptomId = bindingModel.SymptomId; } public MedicamentViewModel GetViewModel => new() { Id = Id, Name = Name, Comment = Comment, ProcedureId = Procedure?.Id ?? null, SymptomId = Symptom?.Id ?? null, SymptomName = Symptom?.Name ?? string.Empty, ProcedureName = Procedure?.Name ?? string.Empty, }; } }