diff --git a/Hospital/HospitalWebApp/Controllers/HomeController.cs b/Hospital/HospitalWebApp/Controllers/HomeController.cs index ebf84d6..2d1cb3e 100644 --- a/Hospital/HospitalWebApp/Controllers/HomeController.cs +++ b/Hospital/HospitalWebApp/Controllers/HomeController.cs @@ -1,28 +1,173 @@ -using HospitalWebApp.Models; +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDataModels.Enums; +using HospitalWebApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; namespace HospitalWebApp.Controllers { + /// + /// Главный контроллер + /// public class HomeController : Controller { + /// + /// Логгер + /// private readonly ILogger _logger; + /// + /// Конструктор + /// + /// public HomeController(ILogger logger) { _logger = logger; } - public IActionResult Index() + /// + /// Домашняя страница + /// + /// + [HttpGet] + public IActionResult MainPage() { - return View(); + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.Doctor); } + /// + /// Личные данные доктора + /// + /// + [HttpGet] public IActionResult Privacy() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.Doctor); + } + + /// + /// Личные данные доктора + /// + /// + /// + /// + /// + /// + [HttpPost] + public void Privacy(string fullname, DoctorPost post, string email, string password) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введены не все данные!"); + } + + APIClient.PostRequest("api/doctor/update", new DoctorBindingModel + { + Id = APIClient.Doctor.Id, + FullName = fullname, + Post = post, + Email = email, + Password = password + }); + + APIClient.Doctor.FullName = fullname; + APIClient.Doctor.Post = post; + APIClient.Doctor.Email = email; + APIClient.Doctor.Password = password; + + Response.Redirect("Privacy"); + } + + /// + /// Аутентификация + /// + /// + [HttpGet] + public IActionResult Enter() { return View(); } + /// + /// Аутентификация + /// + /// + /// + /// + [HttpPost] + public void Enter(string email, string password) + { + if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введены не все данные!"); + } + + APIClient.Doctor = APIClient.GetRequest($"api/doctor/login?email={email}&password={password}"); + if (APIClient.Doctor == null) + { + throw new Exception("Неверный логин/пароль"); + } + + Response.Redirect("MainPage"); + } + + /// + /// Регистрация + /// + /// + [HttpGet] + public IActionResult Register() + { + return View(); + } + + /// + /// Регистрация + /// + /// + /// + /// + /// + /// + [HttpPost] + public void Register(string fullname, DoctorPost post, string email, string password) + { + if (string.IsNullOrEmpty(fullname) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введены не все данные!"); + } + + APIClient.PostRequest("api/doctor/register", new DoctorBindingModel + { + FullName = fullname, + Post = post, + Email = email, + Password = password + }); + + Response.Redirect("Enter"); + } + + /// + /// Ошибка + /// + /// [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/Hospital/HospitalWebApp/Controllers/PatientController.cs b/Hospital/HospitalWebApp/Controllers/PatientController.cs index 38ee3b0..cf8a338 100644 --- a/Hospital/HospitalWebApp/Controllers/PatientController.cs +++ b/Hospital/HospitalWebApp/Controllers/PatientController.cs @@ -3,6 +3,7 @@ using HospitalContracts.BusinessLogicsContracts; using HospitalContracts.ViewModels; using HospitalDataModels.Models; using Microsoft.AspNetCore.Mvc; +using System.Numerics; namespace HospitalWebApp.Controllers { @@ -88,6 +89,7 @@ namespace HospitalWebApp.Controllers FullName = fullname, BirthDate = birthdate, Phone = phone, + DoctorId = APIClient.Doctor.Id, PatientProcedures = patientProcedures }); @@ -143,6 +145,7 @@ namespace HospitalWebApp.Controllers FullName = fullname, BirthDate = birthdate, Phone = phone, + DoctorId = APIClient.Doctor.Id, PatientProcedures = patientProcedures }); @@ -168,5 +171,63 @@ namespace HospitalWebApp.Controllers Response.Redirect("Patients"); } + + /// + /// Выписать рецепт пациенту + /// + /// + /// + [HttpGet] + public IActionResult CreatePatientRecipe() + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + ViewBag.Patients = APIClient.GetRequest>($"api/patient/getpatients?doctorId={APIClient.Doctor.Id}"); + ViewBag.Recipes = APIClient.GetRequest>($"api/recipe/getrecipes?doctorId={APIClient.Doctor.Id}"); + return View(); + } + + /// + /// Выписать рецепт пациенту + /// + /// + /// + /// + [HttpPost] + public void CreatePatientRecipe(int patientId, List recipes) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (patientId <= 0 || recipes == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary patientRecipes = new Dictionary(); + foreach (var recipeId in recipes) + { + patientRecipes.Add(recipeId, APIClient.GetRequest($"api/recipe/getrecipe?id={recipeId}")); + } + + var patient = APIClient.GetRequest($"api/patient/getpatient?id={patientId}"); + APIClient.PostRequest("api/patient/updatepatient", new PatientBindingModel + { + Id = patient!.Id, + FullName = patient!.FullName, + BirthDate = patient!.BirthDate, + Phone = patient!.Phone, + DoctorId = APIClient.Doctor.Id, + PatientProcedures = patient!.PatientProcedures, + PatientRecipes = patientRecipes + }); + + Response.Redirect("Patients"); + } } } diff --git a/Hospital/HospitalWebApp/Controllers/RecipeController.cs b/Hospital/HospitalWebApp/Controllers/RecipeController.cs new file mode 100644 index 0000000..15dd15a --- /dev/null +++ b/Hospital/HospitalWebApp/Controllers/RecipeController.cs @@ -0,0 +1,167 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDataModels.Models; +using Microsoft.AspNetCore.Mvc; +using System.Numerics; + +namespace HospitalWebApp.Controllers +{ + /// + /// Контроллер для сущности "Рецепт" + /// + public class RecipeController : Controller + { + /// + /// Логгер + /// + private readonly ILogger _logger; + + /// + /// Конструктор + /// + /// + public RecipeController(ILogger logger) + { + _logger = logger; + } + + /// + /// Вывести список рецептов + /// + /// + [HttpGet] + public IActionResult Recipes() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + return View(APIClient.GetRequest>($"api/recipe/getrecipes?doctorId={APIClient.Doctor.Id}")); + } + + /// + /// Создать рецепт + /// + /// + [HttpGet] + public IActionResult CreateRecipe() + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Medicines = APIClient.GetRequest>("api/medicine/getmedicines"); + return View(); + } + + /// + /// Создать рецепт + /// + /// + /// + /// + [HttpPost] + public void CreateRecipe(DateTime issuedate, List medicines) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (issuedate == DateTime.MinValue || medicines == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary recipeMedicines = new Dictionary(); + foreach (var medicineId in medicines) + { + recipeMedicines.Add(medicineId, APIClient.GetRequest($"api/medicine/getmedicine?id={medicineId}")); + } + + APIClient.PostRequest("api/recipe/createrecipe", new RecipeBindingModel + { + IssueDate = issuedate, + DoctorId = APIClient.Doctor.Id, + RecipeMedicines = recipeMedicines + }); + + Response.Redirect("Recipes"); + } + + /// + /// Редактировать рецепт + /// + /// + [HttpGet] + public IActionResult UpdateRecipe(int id) + { + if (APIClient.Doctor == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.Medicines = APIClient.GetRequest>("api/medicine/getmedicines"); + return View(APIClient.GetRequest($"api/patient/getpatient?id={id}")); + } + + /// + /// Редактировать рецепт + /// + /// + /// + /// + /// + [HttpPost] + public void UpdateRecipe(int id, DateTime issuedate, List medicines) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (issuedate == DateTime.MinValue || medicines == null) + { + throw new Exception("Введены не все данные!"); + } + + Dictionary recipeMedicines = new Dictionary(); + foreach (var medicineId in medicines) + { + recipeMedicines.Add(medicineId, APIClient.GetRequest($"api/medicine/getmedicine?id={medicineId}")); + } + + APIClient.PostRequest("api/recipe/updaterecipe", new RecipeBindingModel + { + Id = id, + IssueDate = issuedate, + DoctorId = APIClient.Doctor.Id, + RecipeMedicines = recipeMedicines + }); + + Response.Redirect("Recipes"); + } + + /// + /// Удалить рецепт + /// + /// + [HttpPost] + public void DeleteRecipe(int id) + { + if (APIClient.Doctor == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + APIClient.PostRequest($"api/recipe/deleterecipe", new RecipeBindingModel + { + Id = id + }); + + Response.Redirect("Recipes"); + } + } +} diff --git a/Hospital/HospitalWebApp/Views/Home/Privacy.cshtml b/Hospital/HospitalWebApp/Views/Home/Privacy.cshtml index 5a48290..6c2a35d 100644 --- a/Hospital/HospitalWebApp/Views/Home/Privacy.cshtml +++ b/Hospital/HospitalWebApp/Views/Home/Privacy.cshtml @@ -1,4 +1,5 @@ @using HospitalContracts.ViewModels +@using HospitalDataModels.Enums @model DoctorViewModel @@ -20,7 +21,15 @@
Должность:
-
+
+ +
diff --git a/Hospital/HospitalWebApp/Views/Recipe/CreatePatientRecipe.cshtml b/Hospital/HospitalWebApp/Views/Patient/CreatePatientRecipe.cshtml similarity index 93% rename from Hospital/HospitalWebApp/Views/Recipe/CreatePatientRecipe.cshtml rename to Hospital/HospitalWebApp/Views/Patient/CreatePatientRecipe.cshtml index e7d10fa..20647d2 100644 --- a/Hospital/HospitalWebApp/Views/Recipe/CreatePatientRecipe.cshtml +++ b/Hospital/HospitalWebApp/Views/Patient/CreatePatientRecipe.cshtml @@ -11,7 +11,7 @@
Пациенты:
- @foreach (var patient in ViewBag.Patients) {