Rogashova_E.A._CourseWork_H.../HospitalDataBaseImplements/Models/Recipes.cs

101 lines
3.3 KiB
C#
Raw Normal View History

2023-04-05 23:24:58 +04:00
using HospitalContracts.BindingModels;
using HospitalContracts.ViewModels;
using HospitalDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HospitalDataBaseImplements.Models
{
public class Recipes : IRecipesModel
{
public int Id { get; private set; }
[Required]
public string Dose { get; private set; } = string.Empty;
[Required]
public DateTime Date { get; private set; } = DateTime.Now;
public int MedicinesId { get; private set; }
[Required]
public string ModeOfApplication { get; private set; } = string.Empty;
private Dictionary<int, (IProceduresModel, int)>? _recipeProcedures = null;
[NotMapped]
public Dictionary<int, (IProceduresModel, int)> RecipeProcedures
{
get
{
if (_recipeProcedures == null)
{
// _illnessProcedures = Procedures.ToDictionary(recPC => recPC.KurseId, recPC =>
//(recPC.Kurse as IProceduresModel, recPC.Count));
}
return _recipeProcedures;
}
}
[ForeignKey("ProceduresId")] /////////////////
public virtual List<RecipesProcedures> Procedures { get; set; } = new();
private Dictionary<int, (ISymptomsModel, int)>? _recipeSymptoms = null;
[NotMapped]
public Dictionary<int, (ISymptomsModel, int)> RecipeSymptoms
{
get
{
if (_recipeSymptoms == null)
{
// _recipeSymptoms = Symptoms.ToDictionary(recPC => recPC.SymptomsId, recPC => (recPC.Symptoms as ISymptomsModel, recPC.Count));
}
return _recipeSymptoms;
}
}
[ForeignKey("SymptomsId")] /////////////////
public virtual List<RecipesSymptoms> Symptoms { get; set; } = new();
//[Required]
//public int SymptomsId { get; private set; }
//public string SymptomsName { get; private set; } = string.Empty;
//public virtual Symptoms Symptoms { get; set; } = new();
public static Recipes? Create(RecipesBindingModel? model)
{
if (model == null)
{
return null;
}
return new Recipes()
{
Id = model.Id,
Dose = model.Dose,
Date = model.Date,
ModeOfApplication = model.ModeOfApplication,
//SymptomsId = model.SymptomsId,
//SymptomsName = model.SymptomsName
};
}
public void Update(RecipesBindingModel? model)
{
if (model == null)
{
return;
}
Dose = model.Dose;
Date = model.Date;
ModeOfApplication = model.ModeOfApplication;
//SymptomsName = model.SymptomsName;
}
public RecipesViewModel GetViewModel => new()
{
Id = Id,
Dose = Dose,
Date = Date,
ModeOfApplication = ModeOfApplication,
//SymptomsId = SymptomsId,
//SymptomsName = SymptomsName
};
}
}