using HospitalContracts.BindingModels; using HospitalContracts.ViewModels; using HospitalDataModels.Models; using Microsoft.AspNetCore.Mvc; namespace HospitalWebApp.Controllers { /// /// Контроллер для сущности "Болезнь" /// public class DiseaseController : Controller { /// /// Логгер /// private readonly ILogger _logger; /// /// Конструктор /// /// public DiseaseController(ILogger logger) { _logger = logger; } /// /// Вывести список болезней /// /// [HttpGet] public IActionResult Diseases() { if (APIClient.Doctor == null) { return Redirect("~/Home/Enter"); } return View(APIClient.GetRequest>($"api/disease/getdiseases")); } /// /// Создать болезнь /// /// [HttpGet] public IActionResult CreateDisease() { if (APIClient.Doctor == null) { return Redirect("~/Home/Enter"); } ViewBag.Recipes = APIClient.GetRequest>($"api/recipe/getrecipes?doctorId={APIClient.Doctor.Id}"); return View(); } /// /// Создать болезнь /// /// /// /// /// [HttpPost] public void CreateDisease(string name, string? symptoms, int recipeId) { if (APIClient.Doctor == null) { throw new Exception("Необходимо авторизоваться!"); } if (string.IsNullOrEmpty(name) || recipeId <= 0) { throw new Exception("Введены не все данные!"); } APIClient.PostRequest("api/disease/createdisease", new DiseaseBindingModel { Name = name, Symptoms = symptoms, RecipeId = recipeId }); Response.Redirect("Diseases"); } /// /// Редактировать болезнь /// /// [HttpGet] public IActionResult UpdateDisease(int id) { if (APIClient.Doctor == null) { return Redirect("~/Home/Enter"); } ViewBag.Recipes = APIClient.GetRequest>($"api/recipe/getrecipes?doctorId={APIClient.Doctor.Id}"); return View(APIClient.GetRequest($"api/disease/getdisease?id={id}")); } /// /// Редактировать болезнь /// /// /// /// /// /// /// [HttpPost] public void UpdateDisease(int id, string name, string? symptoms, int recipeId) { if (APIClient.Doctor == null) { throw new Exception("Необходимо авторизоваться!"); } if (string.IsNullOrEmpty(name) || recipeId <= 0) { throw new Exception("Введены не все данные!"); } APIClient.PostRequest("api/disease/updatedisease", new DiseaseBindingModel { Id = id, Name = name, Symptoms = symptoms, RecipeId = recipeId }); Response.Redirect("Diseases"); } /// /// Удалить болезнь /// /// [HttpPost] public void DeleteDisease(int id) { if (APIClient.Doctor == null) { throw new Exception("Необходимо авторизоваться!"); } APIClient.PostRequest($"api/disease/deletedisease", new DiseaseBindingModel { Id = id }); Response.Redirect("Diseases"); } } }