103 lines
2.8 KiB
C#
103 lines
2.8 KiB
C#
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 HospitalDatabaseImplement.Models
|
|
{
|
|
/// <summary>
|
|
/// Сущность "Болезнь"
|
|
/// </summary>
|
|
public class Disease : IDiseaseModel
|
|
{
|
|
/// <summary>
|
|
/// Идентификатор
|
|
/// </summary>
|
|
public int Id { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Название болезни
|
|
/// </summary>
|
|
[Required]
|
|
[MaxLength(30)]
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
/// <summary>
|
|
/// Симптомы заболевания
|
|
/// </summary>
|
|
[MaxLength(100)]
|
|
public string? Symptoms { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Идентификатор рецепта
|
|
/// </summary>
|
|
[ForeignKey("RecipeId")]
|
|
public int RecipeId { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Сущность "Рецепт"
|
|
/// </summary>
|
|
public virtual Recipe Recipe { get; private set; } = new();
|
|
|
|
/// <summary>
|
|
/// Создать сущность
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public static Disease? Create(HospitalDatabase context, DiseaseBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new Disease()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Symptoms = model.Symptoms,
|
|
RecipeId = model.RecipeId,
|
|
Recipe = context.Recipes
|
|
.First(x => x.Id == model.RecipeId)
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Изменить сущность
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
public void Update(HospitalDatabase context, DiseaseBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Name = model.Name;
|
|
Symptoms = model.Symptoms;
|
|
RecipeId = model.RecipeId;
|
|
Recipe = context.Recipes
|
|
.First(x => x.Id == model.RecipeId);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Получить модель представления
|
|
/// </summary>
|
|
public DiseaseViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
Symptoms = Symptoms,
|
|
RecipeId = RecipeId
|
|
};
|
|
}
|
|
}
|