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 DiseaseController : Controller
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логгер
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ILogger<DiseaseController> _logger;
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для сущности "Болезнь"
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IDiseaseLogic _diseaseLogic;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Бизнес-логика для сущности "Рецепт"
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IRecipeLogic _recipeLogic;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger"></param>
|
|
|
|
|
/// <param name="diseaseLogic"></param>
|
|
|
|
|
/// <param name="recipeLogic"></param>
|
|
|
|
|
public DiseaseController(ILogger<DiseaseController> logger, IDiseaseLogic diseaseLogic, IRecipeLogic recipeLogic)
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_diseaseLogic = diseaseLogic;
|
|
|
|
|
_recipeLogic = recipeLogic;
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Вывести список болезней
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Diseases()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
return View(_diseaseLogic.ReadList(null));
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать болезнь
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult CreateDisease()
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
ViewBag.Recipes = _recipeLogic.ReadList(new RecipeSearchModel
|
|
|
|
|
{
|
|
|
|
|
DoctorId = APIClient.Doctor.Id,
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-22 00:58:17 +04:00
|
|
|
|
return View();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создать болезнь
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <param name="symptoms"></param>
|
|
|
|
|
/// <param name="recipeId"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
2024-05-25 23:29:08 +04:00
|
|
|
|
public void CreateDisease(string name, string? symptoms, int recipe)
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
if (string.IsNullOrEmpty(name) || recipe <= 0)
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_diseaseLogic.Create(new DiseaseBindingModel
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
Name = name,
|
|
|
|
|
Symptoms = symptoms,
|
2024-05-25 23:29:08 +04:00
|
|
|
|
RecipeId = recipe
|
2024-05-22 00:58:17 +04:00
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Disease/Diseases");
|
|
|
|
|
}
|
2024-05-22 00:58:17 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактировать болезнь
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult UpdateDisease(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
return Redirect("~/Home/Enter");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
ViewBag.Recipes = _recipeLogic.ReadList(new RecipeSearchModel
|
|
|
|
|
{
|
|
|
|
|
DoctorId = APIClient.Doctor.Id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return View(_diseaseLogic.ReadElement(new DiseaseSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
}));
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактировать болезнь
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// /// <param name="id"></param>
|
|
|
|
|
/// <param name="name"></param>
|
|
|
|
|
/// <param name="symptoms"></param>
|
|
|
|
|
/// <param name="recipeId"></param>
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
[HttpPost]
|
2024-05-25 23:29:08 +04:00
|
|
|
|
public void UpdateDisease(int id, string name, string? symptoms, int recipe)
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
if (string.IsNullOrEmpty(name) || recipe <= 0)
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
throw new Exception("Введены не все данные!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_diseaseLogic.Update(new DiseaseBindingModel
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id,
|
|
|
|
|
Name = name,
|
|
|
|
|
Symptoms = symptoms,
|
2024-05-25 23:29:08 +04:00
|
|
|
|
RecipeId = recipe
|
2024-05-22 00:58:17 +04:00
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Disease/Diseases");
|
|
|
|
|
}
|
2024-05-22 00:58:17 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удалить болезнь
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void DeleteDisease(int id)
|
|
|
|
|
{
|
|
|
|
|
if (APIClient.Doctor == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Необходимо авторизоваться!");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
_diseaseLogic.Delete(new DiseaseBindingModel
|
2024-05-22 00:58:17 +04:00
|
|
|
|
{
|
|
|
|
|
Id = id
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-25 23:29:08 +04:00
|
|
|
|
Response.Redirect("/Disease/Diseases");
|
|
|
|
|
}
|
2024-05-22 00:58:17 +04:00
|
|
|
|
}
|
|
|
|
|
}
|