WebApp WIP / Add more controllers
This commit is contained in:
parent
df9d9f6dcc
commit
bcb3888c57
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Главный контроллер
|
||||
/// </summary>
|
||||
public class HomeController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
/// <summary>
|
||||
/// Домашняя страница
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult MainPage()
|
||||
{
|
||||
return View();
|
||||
if (APIClient.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
return View(APIClient.Doctor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Личные данные доктора
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
if (APIClient.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
return View(APIClient.Doctor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Личные данные доктора
|
||||
/// </summary>
|
||||
/// <param name="fullname"></param>
|
||||
/// <param name="post"></param>
|
||||
/// <param name="email"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Аутентификация
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Аутентификация
|
||||
/// </summary>
|
||||
/// <param name="email"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[HttpPost]
|
||||
public void Enter(string email, string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
APIClient.Doctor = APIClient.GetRequest<DoctorViewModel>($"api/doctor/login?email={email}&password={password}");
|
||||
if (APIClient.Doctor == null)
|
||||
{
|
||||
throw new Exception("Неверный логин/пароль");
|
||||
}
|
||||
|
||||
Response.Redirect("MainPage");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Регистрация
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Регистрация
|
||||
/// </summary>
|
||||
/// <param name="fullname"></param>
|
||||
/// <param name="post"></param>
|
||||
/// <param name="email"></param>
|
||||
/// <param name="password"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ошибка
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выписать рецепт пациенту
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[HttpGet]
|
||||
public IActionResult CreatePatientRecipe()
|
||||
{
|
||||
if (APIClient.Doctor == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
ViewBag.Patients = APIClient.GetRequest<List<PatientViewModel>>($"api/patient/getpatients?doctorId={APIClient.Doctor.Id}");
|
||||
ViewBag.Recipes = APIClient.GetRequest<List<RecipeViewModel>>($"api/recipe/getrecipes?doctorId={APIClient.Doctor.Id}");
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выписать рецепт пациенту
|
||||
/// </summary>
|
||||
/// <param name="patientId"></param>
|
||||
/// <param name="recipes"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[HttpPost]
|
||||
public void CreatePatientRecipe(int patientId, List<int> recipes)
|
||||
{
|
||||
if (APIClient.Doctor == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
if (patientId <= 0 || recipes == null)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
Dictionary<int, IRecipeModel> patientRecipes = new Dictionary<int, IRecipeModel>();
|
||||
foreach (var recipeId in recipes)
|
||||
{
|
||||
patientRecipes.Add(recipeId, APIClient.GetRequest<RecipeViewModel>($"api/recipe/getrecipe?id={recipeId}"));
|
||||
}
|
||||
|
||||
var patient = APIClient.GetRequest<PatientViewModel>($"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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
167
Hospital/HospitalWebApp/Controllers/RecipeController.cs
Normal file
167
Hospital/HospitalWebApp/Controllers/RecipeController.cs
Normal file
@ -0,0 +1,167 @@
|
||||
using HospitalContracts.BindingModels;
|
||||
using HospitalContracts.ViewModels;
|
||||
using HospitalDataModels.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Numerics;
|
||||
|
||||
namespace HospitalWebApp.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Контроллер для сущности "Рецепт"
|
||||
/// </summary>
|
||||
public class RecipeController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger<RecipeController> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
public RecipeController(ILogger<RecipeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывести список рецептов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult Recipes()
|
||||
{
|
||||
if (APIClient.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
return View(APIClient.GetRequest<List<RecipeViewModel>>($"api/recipe/getrecipes?doctorId={APIClient.Doctor.Id}"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать рецепт
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult CreateRecipe()
|
||||
{
|
||||
if (APIClient.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Medicines = APIClient.GetRequest<List<MedicineViewModel>>("api/medicine/getmedicines");
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать рецепт
|
||||
/// </summary>
|
||||
/// <param name="issuedate"></param>
|
||||
/// <param name="medicines"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[HttpPost]
|
||||
public void CreateRecipe(DateTime issuedate, List<int> medicines)
|
||||
{
|
||||
if (APIClient.Doctor == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
if (issuedate == DateTime.MinValue || medicines == null)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
Dictionary<int, IMedicineModel> recipeMedicines = new Dictionary<int, IMedicineModel>();
|
||||
foreach (var medicineId in medicines)
|
||||
{
|
||||
recipeMedicines.Add(medicineId, APIClient.GetRequest<MedicineViewModel>($"api/medicine/getmedicine?id={medicineId}"));
|
||||
}
|
||||
|
||||
APIClient.PostRequest("api/recipe/createrecipe", new RecipeBindingModel
|
||||
{
|
||||
IssueDate = issuedate,
|
||||
DoctorId = APIClient.Doctor.Id,
|
||||
RecipeMedicines = recipeMedicines
|
||||
});
|
||||
|
||||
Response.Redirect("Recipes");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать рецепт
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult UpdateRecipe(int id)
|
||||
{
|
||||
if (APIClient.Doctor == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Medicines = APIClient.GetRequest<List<MedicineViewModel>>("api/medicine/getmedicines");
|
||||
return View(APIClient.GetRequest<PatientViewModel>($"api/patient/getpatient?id={id}"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать рецепт
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="issuedate"></param>
|
||||
/// <param name="medicines"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[HttpPost]
|
||||
public void UpdateRecipe(int id, DateTime issuedate, List<int> medicines)
|
||||
{
|
||||
if (APIClient.Doctor == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
if (issuedate == DateTime.MinValue || medicines == null)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
Dictionary<int, IMedicineModel> recipeMedicines = new Dictionary<int, IMedicineModel>();
|
||||
foreach (var medicineId in medicines)
|
||||
{
|
||||
recipeMedicines.Add(medicineId, APIClient.GetRequest<MedicineViewModel>($"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");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить рецепт
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[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");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
@using HospitalContracts.ViewModels
|
||||
@using HospitalDataModels.Enums
|
||||
|
||||
@model DoctorViewModel
|
||||
|
||||
@ -20,7 +21,15 @@
|
||||
<!-- Должность -->
|
||||
<div class="row">
|
||||
<div class="col-4">Должность:</div>
|
||||
<div class="col-8"><input type="text" name="post" value="@Model.Post" /></div>
|
||||
<div class="col-8">
|
||||
<select name="post">
|
||||
<option id="@DoctorPost.Главный_врач" value="@DoctorPost.Главный_врач" selected="@(Model.Post == DoctorPost.Главный_врач ? "selected" : "")">Главный врач</option>
|
||||
<option id="@DoctorPost.Терапевт" value="@DoctorPost.Терапевт" selected="@(Model.Post == DoctorPost.Терапевт ? "selected" : "")">Терапевт</option>
|
||||
<option id="@DoctorPost.Педиатр" value="@DoctorPost.Педиатр" selected="@(Model.Post == DoctorPost.Педиатр ? "selected" : "")">Педиатр</option>
|
||||
<option id="@DoctorPost.Медсестра" value="@DoctorPost.Медсестра" selected="@(Model.Post == DoctorPost.Медсестра ? "selected" : "")">Медсестра</option>
|
||||
<option id="@DoctorPost.Медбрат" value="@DoctorPost.Медбрат" selected="@(Model.Post == DoctorPost.Медбрат ? "selected" : "")">Медбрат</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Логин -->
|
||||
|
@ -11,7 +11,7 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Пациенты:</div>
|
||||
<div class="col-8">
|
||||
<select name="patients" id="patients" class="form-control">
|
||||
<select name="patientId" id="patientId" class="form-control">
|
||||
@foreach (var patient in ViewBag.Patients)
|
||||
{
|
||||
<option value="@patient.Id">@patient.FullName</option>
|
Loading…
Reference in New Issue
Block a user