PIbd-21_CourseWork_Polyclin.../Polyclinic/PolyclinicDatabaseImplement/Models/Medicament.cs

57 lines
1.6 KiB
C#
Raw Normal View History

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;
[Required]
public int ProcedureId { get; set; }
[Required]
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;
}
public MedicamentViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Comment = Comment,
ProcedureId = ProcedureId,
SymptomId = Symptom?.Id ?? null,
SymptomName = Symptom?.Name ?? string.Empty,
ProcedureName = Procedure?.Name ?? string.Empty,
};
}
}