2024-05-23 01:38:16 +04:00
|
|
|
|
using HospitalContracts.BindingModels;
|
2024-05-25 23:29:08 +04:00
|
|
|
|
using HospitalContracts.BusinessLogicsContracts;
|
|
|
|
|
using HospitalContracts.SearchModels;
|
2024-05-23 01:38:16 +04:00
|
|
|
|
using HospitalContracts.ViewModels;
|
|
|
|
|
using HospitalDataModels.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Numerics;
|
|
|
|
|
|
|
|
|
|
namespace HospitalWebApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер для сущности "Рецепт"
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class RecipeController : Controller
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логгер
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ILogger<RecipeController> _logger;
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для сущности "Рецепт"
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IRecipeLogic _recipeLogic;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для сущности "Лекарство"
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IMedicineLogic _medicineLogic;
|
|
|
|
|
|
2024-05-23 01:38:16 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger"></param>
|
2024-05-25 23:29:08 +04:00
|
|
|
|
/// <param name="recipeLogic"></param>
|
|
|
|
|
/// <param name="medicineLogic"></param>
|
|
|
|
|
public RecipeController(ILogger<RecipeController> logger, IRecipeLogic recipeLogic, IMedicineLogic medicineLogic)
|
2024-05-23 01:38:16 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_recipeLogic = recipeLogic;
|
|
|
|
|
_medicineLogic = medicineLogic;
|
2024-05-23 01:38:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Вывести список рецептов
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Recipes()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
return View(_recipeLogic.ReadList(new RecipeSearchModel
|
|
|
|
|
{
|
|
|
|
|
DoctorId = APIClient.Doctor.Id,
|
|
|
|
|
}));
|
2024-05-23 01:38:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать рецепт
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateRecipe()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
ViewBag.Medicines = _medicineLogic.ReadList(null);
|
2024-05-23 01:38:16 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать рецепт
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="issuedate"></param>
|
|
|
|
|
/// <param name="medicines"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateRecipe(DateTime issuedate, List<int> medicines)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (issuedate == DateTime.MinValue || medicines == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<int, IMedicineModel> recipeMedicines = new Dictionary<int, IMedicineModel>();
|
|
|
|
|
foreach (var medicineId in medicines)
|
|
|
|
|
{
|
2024-05-25 23:29:08 +04:00
|
|
|
|
recipeMedicines.Add(medicineId, _medicineLogic.ReadElement(new MedicineSearchModel { Id = medicineId })!);
|
2024-05-23 01:38:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_recipeLogic.Create(new RecipeBindingModel
|
2024-05-23 01:38:16 +04:00
|
|
|
|
{
|
|
|
|
|
IssueDate = issuedate,
|
|
|
|
|
DoctorId = APIClient.Doctor.Id,
|
|
|
|
|
RecipeMedicines = recipeMedicines
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Recipe/Recipes");
|
2024-05-23 01:38:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактировать рецепт
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UpdateRecipe(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
ViewBag.Medicines = _medicineLogic.ReadList(null);
|
|
|
|
|
|
|
|
|
|
return View(_recipeLogic.ReadElement(new RecipeSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}));
|
2024-05-23 01:38:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактировать рецепт
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="issuedate"></param>
|
|
|
|
|
/// <param name="medicines"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateRecipe(int id, DateTime issuedate, List<int> medicines)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (issuedate == DateTime.MinValue || medicines == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<int, IMedicineModel> recipeMedicines = new Dictionary<int, IMedicineModel>();
|
|
|
|
|
foreach (var medicineId in medicines)
|
|
|
|
|
{
|
2024-05-25 23:29:08 +04:00
|
|
|
|
recipeMedicines.Add(medicineId, _medicineLogic.ReadElement(new MedicineSearchModel { Id = medicineId })!);
|
2024-05-23 01:38:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_recipeLogic.Update(new RecipeBindingModel
|
2024-05-23 01:38:16 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
IssueDate = issuedate,
|
|
|
|
|
DoctorId = APIClient.Doctor.Id,
|
|
|
|
|
RecipeMedicines = recipeMedicines
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Recipe/Recipes");
|
2024-05-23 01:38:16 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удалить рецепт
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteRecipe(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_recipeLogic.Delete(new RecipeBindingModel
|
2024-05-23 01:38:16 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Recipe/Recipes");
|
2024-05-23 01:38:16 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|