WebApp WIP / Add controllers

This commit is contained in:
parent 023b71c547
commit df9d9f6dcc
5 changed files with 644 additions and 2 deletions

View File

@ -0,0 +1,156 @@
using HospitalContracts.BindingModels;
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;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="logger"></param>
public DiseaseController(ILogger<DiseaseController> logger)
{
_logger = logger;
}
/// <summary>
/// Вывести список болезней
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Diseases()
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<DiseaseViewModel>>($"api/disease/getdiseases"));
}
/// <summary>
/// Создать болезнь
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult CreateDisease()
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Recipes = APIClient.GetRequest<List<RecipeViewModel>>($"api/recipe/getrecipes?doctorId={APIClient.Doctor.Id}");
return View();
}
/// <summary>
/// Создать болезнь
/// </summary>
/// <param name="name"></param>
/// <param name="symptoms"></param>
/// <param name="recipeId"></param>
/// <exception cref="Exception"></exception>
[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");
}
/// <summary>
/// Редактировать болезнь
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult UpdateDisease(int id)
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Recipes = APIClient.GetRequest<List<RecipeViewModel>>($"api/recipe/getrecipes?doctorId={APIClient.Doctor.Id}");
return View(APIClient.GetRequest<DiseaseViewModel>($"api/disease/getdisease?id={id}"));
}
/// <summary>
/// Редактировать болезнь
/// </summary>
/// /// <param name="id"></param>
/// <param name="name"></param>
/// <param name="symptoms"></param>
/// <param name="recipeId"></param>
/// <exception cref="Exception"></exception>
[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");
}
/// <summary>
/// Удалить болезнь
/// </summary>
/// <returns></returns>
[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");
}
}
}

View File

@ -0,0 +1,149 @@
using HospitalContracts.BindingModels;
using HospitalContracts.ViewModels;
using HospitalDataModels.Models;
using Microsoft.AspNetCore.Mvc;
namespace HospitalWebApp.Controllers
{
/// <summary>
/// Контроллер для сущности "Лекарство"
/// </summary>
public class MedicineController : Controller
{
/// <summary>
/// Логгер
/// </summary>
private readonly ILogger<MedicineController> _logger;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="logger"></param>
public MedicineController(ILogger<MedicineController> logger)
{
_logger = logger;
}
/// <summary>
/// Вывести список лекарств
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Medicines()
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<MedicineViewModel>>($"api/medicine/getmedicines"));
}
/// <summary>
/// Создать лекарство
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult CreateMedicine()
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
/// <summary>
/// Создать лекарство
/// </summary>
/// <param name="name"></param>
/// <param name="description"></param>
/// <exception cref="Exception"></exception>
[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");
}
/// <summary>
/// Редактировать лекарство
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult UpdateMedicine(int id)
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<MedicineViewModel>($"api/medicine/getmedicine?id={id}"));
}
/// <summary>
/// Редактировать лекарство
/// </summary>
/// <param name="name"></param>
/// <param name="description"></param>
/// <exception cref="Exception"></exception>
[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");
}
/// <summary>
/// Удалить лекарство
/// </summary>
/// <returns></returns>
[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");
}
}
}

View File

@ -0,0 +1,172 @@
using HospitalContracts.BindingModels;
using HospitalContracts.BusinessLogicsContracts;
using HospitalContracts.ViewModels;
using HospitalDataModels.Models;
using Microsoft.AspNetCore.Mvc;
namespace HospitalWebApp.Controllers
{
/// <summary>
/// Контроллер для сущности "Пациент"
/// </summary>
public class PatientController : Controller
{
/// <summary>
/// Логгер
/// </summary>
private readonly ILogger<PatientController> _logger;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="logger"></param>
public PatientController(ILogger<PatientController> logger)
{
_logger = logger;
}
/// <summary>
/// Вывести список пациентов
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Patients()
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<PatientViewModel>>($"api/patient/getpatients?doctorId={APIClient.Doctor.Id}"));
}
/// <summary>
/// Создать пациента
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult CreatePatient()
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Procedures = APIClient.GetRequest<List<ProcedureViewModel>>("api/procedure/getprocedures");
return View();
}
/// <summary>
/// Создать пациента
/// </summary>
/// <param name="fullname"></param>
/// <param name="birthdate"></param>
/// <param name="phone"></param>
/// <param name="procedures"></param>
/// <returns></returns>
[HttpPost]
public void CreatePatient(string fullname, DateTime birthdate, string phone, List<int> procedures)
{
if (APIClient.Doctor == null)
{
throw new Exception("Необходимо авторизоваться!");
}
if (string.IsNullOrEmpty(fullname) || birthdate == DateTime.MinValue || string.IsNullOrEmpty(phone) || procedures == null)
{
throw new Exception("Введены не все данные!");
}
Dictionary<int, IProcedureModel> patientProcedures = new Dictionary<int, IProcedureModel>();
foreach (var procedureId in procedures)
{
patientProcedures.Add(procedureId, APIClient.GetRequest<ProcedureViewModel>($"api/procedure/getprocedure?id={procedureId}"));
}
APIClient.PostRequest("api/patient/createpatient", new PatientBindingModel
{
FullName = fullname,
BirthDate = birthdate,
Phone = phone,
PatientProcedures = patientProcedures
});
Response.Redirect("Patients");
}
/// <summary>
/// Редактировать пациента
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult UpdatePatient(int id)
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Procedures = APIClient.GetRequest<List<ProcedureViewModel>>("api/procedure/getprocedures");
return View(APIClient.GetRequest<PatientViewModel>($"api/patient/getpatient?id={id}"));
}
/// <summary>
/// Редактировать пациента
/// </summary>
/// <param name="fullname"></param>
/// <param name="birthdate"></param>
/// <param name="phone"></param>
/// <param name="procedures"></param>
/// <returns></returns>
[HttpPost]
public void UpdatePatient(int id, string fullname, DateTime birthdate, string phone, List<int> procedures)
{
if (APIClient.Doctor == null)
{
throw new Exception("Необходимо авторизоваться!");
}
if (string.IsNullOrEmpty(fullname) || birthdate == DateTime.MinValue || string.IsNullOrEmpty(phone) || procedures == null)
{
throw new Exception("Введены не все данные!");
}
Dictionary<int, IProcedureModel> patientProcedures = new Dictionary<int, IProcedureModel>();
foreach (var procedureId in procedures)
{
patientProcedures.Add(procedureId, APIClient.GetRequest<ProcedureViewModel>($"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");
}
/// <summary>
/// Удалить пациента
/// </summary>
/// <returns></returns>
[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");
}
}
}

View File

@ -0,0 +1,167 @@
using HospitalContracts.BindingModels;
using HospitalContracts.ViewModels;
using HospitalDataModels.Models;
using Microsoft.AspNetCore.Mvc;
namespace HospitalWebApp.Controllers
{
/// <summary>
/// Контроллер для сущности "Процедура"
/// </summary>
public class ProcedureController : Controller
{
/// <summary>
/// Логгер
/// </summary>
private readonly ILogger<ProcedureController> _logger;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="logger"></param>
public ProcedureController(ILogger<ProcedureController> logger)
{
_logger = logger;
}
/// <summary>
/// Вывести список процедур
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Procedures()
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<ProcedureViewModel>>($"api/procedure/getprocedures"));
}
/// <summary>
/// Создать процедуру
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult CreateProcedure()
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Medicines = APIClient.GetRequest<List<MedicineViewModel>>("api/medicine/getmedicines");
return View();
}
/// <summary>
/// Создать процедуру
/// </summary>
/// <param name="name"></param>
/// <param name="description"></param>
/// <param name="medicines"></param>
/// <exception cref="Exception"></exception>
[HttpPost]
public void CreateProcedure(string name, string? description, List<int> medicines)
{
if (APIClient.Doctor == null)
{
throw new Exception("Необходимо авторизоваться!");
}
if (string.IsNullOrEmpty(name) || medicines == null)
{
throw new Exception("Введены не все данные!");
}
Dictionary<int, IMedicineModel> procedureMedicines = new Dictionary<int, IMedicineModel>();
foreach (var medicineId in medicines)
{
procedureMedicines.Add(medicineId, APIClient.GetRequest<MedicineViewModel>($"api/medicine/getmedicine?id={medicineId}"));
}
APIClient.PostRequest("api/procedure/createprocedure", new ProcedureBindingModel
{
Name = name,
Description = description,
ProcedureMedicines = procedureMedicines
});
Response.Redirect("Procedures");
}
/// <summary>
/// Редактировать процедуру
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult UpdateProcedure(int id)
{
if (APIClient.Doctor == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Medicines = APIClient.GetRequest<List<MedicineViewModel>>("api/medicine/getmedicines");
return View(APIClient.GetRequest<ProcedureViewModel>($"api/procedure/getprocedure?id={id}"));
}
/// <summary>
/// Редактировать процедуру
/// </summary>
/// <param name="name"></param>
/// <param name="description"></param>
/// <param name="medicines"></param>
/// <exception cref="Exception"></exception>
[HttpPost]
public void UpdateProcedure(int id, string name, string? description, List<int> medicines)
{
if (APIClient.Doctor == null)
{
throw new Exception("Необходимо авторизоваться!");
}
if (string.IsNullOrEmpty(name) || medicines == null)
{
throw new Exception("Введены не все данные!");
}
Dictionary<int, IMedicineModel> procedureMedicines = new Dictionary<int, IMedicineModel>();
foreach (var medicineId in medicines)
{
procedureMedicines.Add(medicineId, APIClient.GetRequest<MedicineViewModel>($"api/medicine/getmedicine?id={medicineId}"));
}
APIClient.PostRequest("api/procedure/updateprocedure", new ProcedureBindingModel
{
Id = id,
Name = name,
Description = description,
ProcedureMedicines = procedureMedicines
});
Response.Redirect("Procedures");
}
/// <summary>
/// Удалить процедуру
/// </summary>
/// <returns></returns>
[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");
}
}
}

View File

@ -11,9 +11,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HospitalBusinessLogics\HospitalBusinessLogics.csproj" />
<ProjectReference Include="..\HospitalContracts\HospitalContracts.csproj" />
<ProjectReference Include="..\HospitalDatabaseImplement\HospitalDatabaseImplement.csproj" />
<ProjectReference Include="..\HospitalDataModels\HospitalDataModels.csproj" />
</ItemGroup>