82 lines
2.1 KiB
C#
82 lines
2.1 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
|
|
{
|
|
/// <summary>
|
|
/// Сущность "Лекарство"
|
|
/// </summary>
|
|
public class Medicine : IMedicineModel
|
|
{
|
|
/// <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? Description { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Создать сущность
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public static Medicine? Create(MedicineBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return new Medicine()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Description = model.Description
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Изменить сущность
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
public void Update(MedicineBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Name = model.Name;
|
|
Description = model.Description;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Получить модель представления
|
|
/// </summary>
|
|
public MedicineViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
Description = Description
|
|
};
|
|
}
|
|
}
|