2024-05-22 00:58:17 +04:00
|
|
|
|
using HospitalContracts.BindingModels;
|
2024-05-25 23:29:08 +04:00
|
|
|
|
using HospitalContracts.BusinessLogicsContracts;
|
|
|
|
|
using HospitalContracts.SearchModels;
|
2024-05-22 00:58:17 +04:00
|
|
|
|
using HospitalContracts.ViewModels;
|
|
|
|
|
using HospitalDataModels.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace HospitalWebApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер для сущности "Процедура"
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ProcedureController : Controller
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логгер
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ILogger<ProcedureController> _logger;
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для сущности "Процедура"
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IProcedureLogic _procedureLogic;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для сущности "Лекарство"
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IMedicineLogic _medicineLogic;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger"></param>
|
|
|
|
|
/// <param name="procedureLogic"></param>
|
|
|
|
|
/// <param name="medicineLogic"></param>
|
|
|
|
|
public ProcedureController(ILogger<ProcedureController> logger, IProcedureLogic procedureLogic, IMedicineLogic medicineLogic)
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_procedureLogic = procedureLogic;
|
|
|
|
|
_medicineLogic = medicineLogic;
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Вывести список процедур
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Procedures()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
return View(_procedureLogic.ReadList(null));
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать процедуру
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateProcedure()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
ViewBag.Medicines = _medicineLogic.ReadList(null);
|
2024-05-22 00:58:17 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать процедуру
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <param name="description"></param>
|
|
|
|
|
/// <param name="medicines"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateProcedure(string name, string? description, List<int> medicines)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(name) || medicines == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<int, IMedicineModel> procedureMedicines = new Dictionary<int, IMedicineModel>();
|
|
|
|
|
foreach (var medicineId in medicines)
|
|
|
|
|
{
|
2024-05-25 23:29:08 +04:00
|
|
|
|
procedureMedicines.Add(medicineId, _medicineLogic.ReadElement(new MedicineSearchModel { Id = medicineId })!);
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_procedureLogic.Create(new ProcedureBindingModel
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Description = description,
|
|
|
|
|
ProcedureMedicines = procedureMedicines
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Procedure/Procedures");
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактировать процедуру
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UpdateProcedure(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(_procedureLogic.ReadElement(new ProcedureSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}));
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактировать процедуру
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <param name="description"></param>
|
|
|
|
|
/// <param name="medicines"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateProcedure(int id, string name, string? description, List<int> medicines)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(name) || medicines == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Dictionary<int, IMedicineModel> procedureMedicines = new Dictionary<int, IMedicineModel>();
|
|
|
|
|
foreach (var medicineId in medicines)
|
|
|
|
|
{
|
|
|
|
|
procedureMedicines.Add(medicineId, _medicineLogic.ReadElement(new MedicineSearchModel { Id = medicineId })!);
|
|
|
|
|
}
|
2024-05-22 00:58:17 +04:00
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_procedureLogic.Update(new ProcedureBindingModel
|
|
|
|
|
{
|
2024-05-22 00:58:17 +04:00
|
|
|
|
Id = id,
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Name = name,
|
|
|
|
|
Description = description,
|
|
|
|
|
ProcedureMedicines = procedureMedicines
|
|
|
|
|
});
|
2024-05-22 00:58:17 +04:00
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Procedure/Procedures");
|
|
|
|
|
}
|
2024-05-22 00:58:17 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удалить процедуру
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteProcedure(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_procedureLogic.Delete(new ProcedureBindingModel
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Procedure/Procedures");
|
|
|
|
|
}
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|