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 Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace HospitalWebApp.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер для сущности "Лекарство"
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class MedicineController : Controller
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логгер
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ILogger<MedicineController> _logger;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-25 23:29:08 +04:00
|
|
|
|
/// Бизнес-логика для сущности "Лекарство"
|
2024-05-22 00:58:17 +04:00
|
|
|
|
/// </summary>
|
2024-05-25 23:29:08 +04:00
|
|
|
|
private readonly IMedicineLogic _medicineLogic;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger"></param>
|
|
|
|
|
/// <param name="medicineLogic"></param>
|
|
|
|
|
public MedicineController(ILogger<MedicineController> logger, IMedicineLogic medicineLogic)
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_medicineLogic = medicineLogic;
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Вывести список лекарств
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Medicines()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
return View(_medicineLogic.ReadList(null));
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать лекарство
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateMedicine()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать лекарство
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <param name="description"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void CreateMedicine(string name, string? description)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_medicineLogic.Create(new MedicineBindingModel
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Description = description
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Medicine/Medicines");
|
|
|
|
|
}
|
2024-05-22 00:58:17 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактировать лекарство
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UpdateMedicine(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
return View(_medicineLogic.ReadElement(new MedicineSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}));
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактировать лекарство
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <param name="description"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void UpdateMedicine(int id, string name, string? description)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_medicineLogic.Update(new MedicineBindingModel
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
Name = name,
|
|
|
|
|
Description = description
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Medicine/Medicines");
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удалить лекарство
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteMedicine(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_medicineLogic.Delete(new MedicineBindingModel
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Medicine/Medicines");
|
|
|
|
|
}
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|