PIbd-21_CourseWork_Polyclin.../Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs

345 lines
11 KiB
C#
Raw Blame History

using Microsoft.AspNetCore.Mvc;
using PolyclinicBusinessLogic.BusinessLogics;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.SearchModels;
using PolyclinicContracts.ViewModels;
using PolyclinicDataModels.Models;
using PolyclinicWebAppSuretor.Models;
using System.Diagnostics;
namespace PolyclinicWebAppSuretor.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly IProcedureLogic _procedureLogic;
private readonly IMedicamentLogic _medicamentLogic;
private readonly IRecipeLogic _recipeLogic;
private readonly ISymptomLogic _symptomLogic;
private readonly ICourseLogic _courseLogic;
public HomeController(ILogger<HomeController> logger,
IProcedureLogic procedureLogic,
IMedicamentLogic medicamentLogic,
IRecipeLogic recipeLogic,
ISymptomLogic symptomLogic,
ICourseLogic courseLogic)
{
_logger = logger;
_procedureLogic = procedureLogic;
_medicamentLogic = medicamentLogic;
_recipeLogic = recipeLogic;
_symptomLogic = symptomLogic;
_courseLogic = courseLogic;
}
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
return View();
}
public IActionResult Recipes()
{
List<RecipeViewModel> recipes = _recipeLogic.ReadList(null);
if (recipes == null)
{
recipes = new();
}
return View(recipes);
}
[HttpGet]
[HttpPost]
public IActionResult CreateRecipe(RecipeModel model, int[] selectedProcedures)
{
ViewBag.Courses = _courseLogic.ReadList(null);
if (HttpContext.Request.Method == "GET")
{
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
model = new()
{
Procedures = _procedureLogic.ReadList(null).Select(x => (x, false)).ToList()
};
return View("CreateRecipe", model);
}
else
{
var allProcedures = _procedureLogic.ReadList(null);
RecipeBindingModel recipe = new RecipeBindingModel
{
ProceduresCount = model.RecipeViewModel.ProceduresCount,
Comment = model.RecipeViewModel.Comment,
RecipeProcedures = selectedProcedures
.ToDictionary(
x => x,
x => allProcedures.Where(y => y.Id == x) as IProcedureModel
)
};
_recipeLogic.Create(recipe);
return RedirectToAction("Recipes");
}
}
[HttpGet]
[HttpPost]
public IActionResult EditRecipe(int id, RecipeModel model, int[] selectedProcedures)
{
if (HttpContext.Request.Method == "GET")
{
var obj = _recipeLogic.ReadElement(new RecipeSearchModel { Id = id });
model = new()
{
RecipeViewModel = obj,
Procedures = _procedureLogic.ReadList(null).Select(x => (x, obj.RecipeProcedures.ContainsKey(x.Id))).ToList()
};
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
return View("CreateRecipe", model);
}
else
{
var allProcedures = _procedureLogic.ReadList(null);
RecipeBindingModel recipe = new RecipeBindingModel
{
Id = id,
ProceduresCount = model.RecipeViewModel.ProceduresCount,
Comment = model.RecipeViewModel.Comment,
RecipeProcedures = selectedProcedures
.ToDictionary(
x => x,
x => allProcedures.Where(y => y.Id == x) as IProcedureModel
)
};
_recipeLogic.Update(recipe);
return RedirectToAction("Recipes");
}
}
[HttpPost]
public IActionResult DeleteRecipe(int id)
{
var obj = _recipeLogic.ReadElement(new RecipeSearchModel { Id = id });
if (obj != null)
{
_recipeLogic.Delete(new RecipeBindingModel { Id = obj.Id });
}
return RedirectToAction("Recipes");
}
public IActionResult Medicaments()
{
List<MedicamentViewModel> medicaments = _medicamentLogic.ReadList(null);
if (medicaments == null)
{
medicaments = new();
}
return View(medicaments);
}
[HttpGet]
[HttpPost]
public IActionResult CreateMedicament(MedicamentViewModel model)
{
ViewBag.Procedures = _procedureLogic.ReadList(null);
ViewBag.Symptomes = _symptomLogic.ReadList(null);
if (HttpContext.Request.Method == "GET")
{
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
return View();
}
else
{
// TODO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UserId
MedicamentBindingModel medicament = new MedicamentBindingModel
{
Name = model.Name,
Comment = model.Comment ?? string.Empty,
SymptomId = model.SymptomId,
ProcedureId = model.ProcedureId,
};
_medicamentLogic.Create(medicament);
return RedirectToAction("Medicaments");
}
}
[HttpGet]
[HttpPost]
public IActionResult EditMedicament(MedicamentViewModel model)
{
if (HttpContext.Request.Method == "GET")
{
var obj = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = model.Id });
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
return View("CreateMedicament", obj);
}
else
{
MedicamentBindingModel medicament = new MedicamentBindingModel
{
Id = model.Id,
Name = model.Name,
Comment = model.Comment ?? string.Empty,
SymptomId = model.SymptomId,
ProcedureId = model.ProcedureId,
};
_medicamentLogic.Update(medicament);
return RedirectToAction("Medicaments");
}
}
[HttpPost]
public IActionResult DeleteMedicament(int id)
{
var obj = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = id });
if (obj != null)
{
_medicamentLogic.Delete(new MedicamentBindingModel { Id = obj.Id });
}
return RedirectToAction("Medicaments");
}
public IActionResult Procedures()
{
List<ProcedureViewModel> procedure = _procedureLogic.ReadList(null);
if (procedure == null)
{
procedure = new();
}
return View(procedure);
}
[HttpGet]
[HttpPost]
public IActionResult CreateProcedure(ProcedureViewModel model)
{
if (HttpContext.Request.Method == "GET")
{
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
return View();
}
else
{
// TODO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> UserId
ProcedureBindingModel procedure = new ProcedureBindingModel
{
Name = model.Name,
Comment = model.Comment ?? string.Empty,
DateStartProcedure = model.DateStartProcedure,
DateStopProcedure = model.DateStopProcedure
};
_procedureLogic.Create(procedure);
return RedirectToAction("Procedures");
}
}
[HttpGet]
[HttpPost]
public IActionResult EditProcedure(ProcedureViewModel model)
{
if (HttpContext.Request.Method == "GET")
{
var obj = _procedureLogic.ReadElement(new ProcedureSearchModel { Id = model.Id });
ViewData["Title"] = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
return View("CreateProcedure", obj);
}
else
{
ProcedureBindingModel procedure = new ProcedureBindingModel
{
Id = model.Id,
Name = model.Name,
Comment = model.Comment,
DateStartProcedure = model.DateStartProcedure,
DateStopProcedure = model.DateStopProcedure
};
_procedureLogic.Update(procedure);
return RedirectToAction("Procedures");
}
}
[HttpPost]
public IActionResult DeleteProcedure(int id)
{
var obj = _procedureLogic.ReadElement(new ProcedureSearchModel { Id = id });
if (obj != null)
{
_procedureLogic.Delete(new ProcedureBindingModel { Id = obj.Id });
}
return RedirectToAction("Procedures");
}
public IActionResult ListCoursesByProcedures()
{
List<ProcedureViewModel> procedures = _procedureLogic.ReadList(null);
return View(procedures);
}
public IActionResult AddSymptomToMedicament(AddSymptomToMedicamentModel model)
{
model = new()
{
Medicaments = _medicamentLogic.ReadList(null),
Symptoms = _symptomLogic.ReadList(null)
};
return View(model);
}
[HttpGet]
[HttpPost]
public IActionResult ProceduresReport()
{
if (HttpContext.Request.Method == "POST")
{
ViewData["ShowReport"] = true;
return View();
}
else
{
return View();
}
}
[HttpGet]
[HttpPost]
public IActionResult Login()
{
if (HttpContext.Request.Method == "POST")
{
// <20><><EFBFBD><EFBFBD><EFBFBD>-<2D><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
return View();
}
else
{
return View();
}
}
[HttpGet]
[HttpPost]
public IActionResult Register()
{
if (HttpContext.Request.Method == "POST")
{
// <20><><EFBFBD><EFBFBD><EFBFBD>-<2D><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return View();
}
else
{
return View();
}
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}