From df9d9f6dcc9fe9ee4781a3296c8c3758a64d880d Mon Sep 17 00:00:00 2001 From: Factorino73 Date: Wed, 22 May 2024 00:58:17 +0400 Subject: [PATCH] WebApp WIP / Add controllers --- .../Controllers/DiseaseController.cs | 156 ++++++++++++++++ .../Controllers/MedicineController.cs | 149 +++++++++++++++ .../Controllers/PatientController.cs | 172 ++++++++++++++++++ .../Controllers/ProcedureController.cs | 167 +++++++++++++++++ Hospital/HospitalWebApp/HospitalWebApp.csproj | 2 - 5 files changed, 644 insertions(+), 2 deletions(-) create mode 100644 Hospital/HospitalWebApp/Controllers/DiseaseController.cs create mode 100644 Hospital/HospitalWebApp/Controllers/MedicineController.cs create mode 100644 Hospital/HospitalWebApp/Controllers/PatientController.cs create mode 100644 Hospital/HospitalWebApp/Controllers/ProcedureController.cs diff --git a/Hospital/HospitalWebApp/Controllers/DiseaseController.cs b/Hospital/HospitalWebApp/Controllers/DiseaseController.cs new file mode 100644 index 0000000..0b81392 --- /dev/null +++ b/Hospital/HospitalWebApp/Controllers/DiseaseController.cs @@ -0,0 +1,156 @@ +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"); + } + } +} diff --git a/Hospital/HospitalWebApp/Controllers/MedicineController.cs b/Hospital/HospitalWebApp/Controllers/MedicineController.cs new file mode 100644 index 0000000..19e83a3 --- /dev/null +++ b/Hospital/HospitalWebApp/Controllers/MedicineController.cs @@ -0,0 +1,149 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDataModels.Models; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalWebApp.Controllers +{ + /// + /// Контроллер для сущности "Лекарство" + /// + public class MedicineController : Controller + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Конструктор + /// + /// + public MedicineController(ILogger logger) + { + _logger = logger; + } + + /// + /// Вывести список лекарств + /// + /// + [HttpGet] + public IActionResult Medicines() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.GetRequest>($"api/medicine/getmedicines")); + } + + /// + /// Создать лекарство + /// + /// + [HttpGet] + public IActionResult CreateMedicine() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + return View(); + } + + /// + /// Создать лекарство + /// + /// + /// + /// + [HttpPost] + public void CreateMedicine(string name, string? description) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Введены не все данные!"); + } + + APIClient.PostRequest("api/medicine/createmedicine", new MedicineBindingModel + { + Name = name, + Description = description + }); + + Response.Redirect("Medicines"); + } + + /// + /// Редактировать лекарство + /// + /// + [HttpGet] + public IActionResult UpdateMedicine(int id) + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.GetRequest($"api/medicine/getmedicine?id={id}")); + } + + /// + /// Редактировать лекарство + /// + /// + /// + /// + [HttpPost] + public void UpdateMedicine(int id, string name, string? description) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Введены не все данные!"); + } + + APIClient.PostRequest("api/medicine/updatemedicine", new MedicineBindingModel + { + Id = id, + Name = name, + Description = description + }); + + Response.Redirect("Medicines"); + } + + /// + /// Удалить лекарство + /// + /// + [HttpPost] + public void DeleteMedicine(int id) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + APIClient.PostRequest($"api/medicine/deletemedicine", new MedicineBindingModel + { + Id = id + }); + + Response.Redirect("Medicines"); + } + } +} diff --git a/Hospital/HospitalWebApp/Controllers/PatientController.cs b/Hospital/HospitalWebApp/Controllers/PatientController.cs new file mode 100644 index 0000000..38ee3b0 --- /dev/null +++ b/Hospital/HospitalWebApp/Controllers/PatientController.cs @@ -0,0 +1,172 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.BusinessLogicsContracts; +using HospitalContracts.ViewModels; +using HospitalDataModels.Models; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalWebApp.Controllers +{ + /// + /// Контроллер для сущности "Пациент" + /// + public class PatientController : Controller + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Конструктор + /// + /// + public PatientController(ILogger logger) + { + _logger = logger; + } + + /// + /// Вывести список пациентов + /// + /// + [HttpGet] + public IActionResult Patients() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.GetRequest>($"api/patient/getpatients?doctorId={APIClient.Doctor.Id}")); + } + + /// + /// Создать пациента + /// + /// + [HttpGet] + public IActionResult CreatePatient() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Procedures = APIClient.GetRequest>("api/procedure/getprocedures"); + return View(); + } + + /// + /// Создать пациента + /// + /// + /// + /// + /// + /// + [HttpPost] + public void CreatePatient(string fullname, DateTime birthdate, string phone, List procedures) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(fullname) || birthdate == DateTime.MinValue || string.IsNullOrEmpty(phone) || procedures == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary patientProcedures = new Dictionary(); + foreach (var procedureId in procedures) + { + patientProcedures.Add(procedureId, APIClient.GetRequest($"api/procedure/getprocedure?id={procedureId}")); + } + + APIClient.PostRequest("api/patient/createpatient", new PatientBindingModel + { + FullName = fullname, + BirthDate = birthdate, + Phone = phone, + PatientProcedures = patientProcedures + }); + + Response.Redirect("Patients"); + } + + /// + /// Редактировать пациента + /// + /// + [HttpGet] + public IActionResult UpdatePatient(int id) + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Procedures = APIClient.GetRequest>("api/procedure/getprocedures"); + return View(APIClient.GetRequest($"api/patient/getpatient?id={id}")); + } + + /// + /// Редактировать пациента + /// + /// + /// + /// + /// + /// + [HttpPost] + public void UpdatePatient(int id, string fullname, DateTime birthdate, string phone, List procedures) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(fullname) || birthdate == DateTime.MinValue || string.IsNullOrEmpty(phone) || procedures == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary patientProcedures = new Dictionary(); + foreach (var procedureId in procedures) + { + patientProcedures.Add(procedureId, APIClient.GetRequest($"api/procedure/getprocedure?id={procedureId}")); + } + + APIClient.PostRequest("api/patient/updatepatient", new PatientBindingModel + { + Id = id, + FullName = fullname, + BirthDate = birthdate, + Phone = phone, + PatientProcedures = patientProcedures + }); + + Response.Redirect("Patients"); + } + + /// + /// Удалить пациента + /// + /// + [HttpPost] + public void DeletePatient(int id) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + APIClient.PostRequest($"api/patient/deletepatient", new PatientBindingModel + { + Id = id + }); + + Response.Redirect("Patients"); + } + } +} diff --git a/Hospital/HospitalWebApp/Controllers/ProcedureController.cs b/Hospital/HospitalWebApp/Controllers/ProcedureController.cs new file mode 100644 index 0000000..f1061ee --- /dev/null +++ b/Hospital/HospitalWebApp/Controllers/ProcedureController.cs @@ -0,0 +1,167 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDataModels.Models; +using Microsoft.AspNetCore.Mvc; + +namespace HospitalWebApp.Controllers +{ + /// + /// Контроллер для сущности "Процедура" + /// + public class ProcedureController : Controller + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Конструктор + /// + /// + public ProcedureController(ILogger logger) + { + _logger = logger; + } + + /// + /// Вывести список процедур + /// + /// + [HttpGet] + public IActionResult Procedures() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.GetRequest>($"api/procedure/getprocedures")); + } + + /// + /// Создать процедуру + /// + /// + [HttpGet] + public IActionResult CreateProcedure() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Medicines = APIClient.GetRequest>("api/medicine/getmedicines"); + return View(); + } + + /// + /// Создать процедуру + /// + /// + /// + /// + /// + [HttpPost] + public void CreateProcedure(string name, string? description, List medicines) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || medicines == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary procedureMedicines = new Dictionary(); + foreach (var medicineId in medicines) + { + procedureMedicines.Add(medicineId, APIClient.GetRequest($"api/medicine/getmedicine?id={medicineId}")); + } + + APIClient.PostRequest("api/procedure/createprocedure", new ProcedureBindingModel + { + Name = name, + Description = description, + ProcedureMedicines = procedureMedicines + }); + + Response.Redirect("Procedures"); + } + + /// + /// Редактировать процедуру + /// + /// + [HttpGet] + public IActionResult UpdateProcedure(int id) + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Medicines = APIClient.GetRequest>("api/medicine/getmedicines"); + return View(APIClient.GetRequest($"api/procedure/getprocedure?id={id}")); + } + + /// + /// Редактировать процедуру + /// + /// + /// + /// + /// + [HttpPost] + public void UpdateProcedure(int id, string name, string? description, List medicines) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(name) || medicines == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary procedureMedicines = new Dictionary(); + foreach (var medicineId in medicines) + { + procedureMedicines.Add(medicineId, APIClient.GetRequest($"api/medicine/getmedicine?id={medicineId}")); + } + + APIClient.PostRequest("api/procedure/updateprocedure", new ProcedureBindingModel + { + Id = id, + Name = name, + Description = description, + ProcedureMedicines = procedureMedicines + }); + + Response.Redirect("Procedures"); + } + + /// + /// Удалить процедуру + /// + /// + [HttpPost] + public void DeleteProcedure(int id) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + APIClient.PostRequest($"api/procedure/deleteprocedure", new ProcedureBindingModel + { + Id = id + }); + + Response.Redirect("Prodecures"); + } + } +} diff --git a/Hospital/HospitalWebApp/HospitalWebApp.csproj b/Hospital/HospitalWebApp/HospitalWebApp.csproj index 4567e9c..ef16dd3 100644 --- a/Hospital/HospitalWebApp/HospitalWebApp.csproj +++ b/Hospital/HospitalWebApp/HospitalWebApp.csproj @@ -11,9 +11,7 @@ - -