CourseWork_Borschevskaya_A..../Hospital/HospitalDatabaseImplement/Models/Prescription.cs

57 lines
1.6 KiB
C#

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 Prescription : IPrescriptionModel
{
public int Id { get; private set; }
[Required]
public DateTime Date { get; private set; } = DateTime.Now;
[Required]
public int Number { get; private set; }
[Required]
public int MedicineId { get; private set; }
public virtual Medicine Medicine { get; set; }
[Required]
public int ApothecaryId { get; private set; }
public virtual Apothecary Apothecary { get; set; }
public static Prescription Create(PrescriptionBindingModel model)
{
return new Prescription()
{
Id = model.Id,
Date = model.Date,
Number = model.Number,
MedicineId = model.MedicineId,
ApothecaryId = model.ApothecaryId
};
}
public void Update(PrescriptionBindingModel model)
{
Number = model.Number;
}
public PrescriptionViewModel GetViewModel => new()
{
Id = Id,
Date = Date,
Number = Number,
MedicineId = MedicineId,
MedicineName = Medicine.Name,
ApothecaryId = ApothecaryId,
ApothecaryLogin = Apothecary.Login
};
}
}