76 lines
2.0 KiB
C#
76 lines
2.0 KiB
C#
using HospitalContracts.BindingModels;
|
|
using HospitalContracts.ViewModels;
|
|
using HospitalDataModels.Models;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace HospitalDatabaseImplement.Models
|
|
{
|
|
public class Medicine : IMedicineModel
|
|
{
|
|
public int Id { get; private set; }
|
|
|
|
[Required]
|
|
[MaxLength(60)]
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
[Required]
|
|
public double Cost { get; private set; }
|
|
|
|
[Required]
|
|
[MaxLength(10)]
|
|
public string Dose { get; private set; } = string.Empty;
|
|
|
|
[Required]
|
|
public int ApothecaryId { get; private set; }
|
|
|
|
public virtual Apothecary Apothecary { get; set; }
|
|
|
|
[ForeignKey("MedicineId")]
|
|
public virtual List<Prescription> Prescriptions { get; set; } = new();
|
|
|
|
[ForeignKey("MedicineId")]
|
|
public virtual List<RecipeMedicine> Recipes { get; set; } = new();
|
|
|
|
[ForeignKey("MedicineId")]
|
|
public virtual List<ProcedureMedicine> Procedures { get; set; } = new();
|
|
|
|
public static Medicine? Create(MedicineBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Medicine()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Cost = model.Cost,
|
|
Dose = model.Dose,
|
|
ApothecaryId = model.ApothecaryId
|
|
};
|
|
}
|
|
|
|
public void Update(MedicineBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Name = model.Name;
|
|
Cost = model.Cost;
|
|
Dose = model.Dose;
|
|
}
|
|
public MedicineViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
Cost = Cost,
|
|
Dose = Dose,
|
|
ApothecaryId = ApothecaryId,
|
|
ApothecaryLogin = Apothecary.Login
|
|
};
|
|
}
|
|
}
|