2024-05-23 14:58:59 +04:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2024-05-26 13:03:03 +04:00
|
|
|
|
using PolyclinicContracts.BindingModels;
|
2024-05-23 14:58:59 +04:00
|
|
|
|
using PolyclinicContracts.BusinessLogicsContracts;
|
2024-05-26 13:03:03 +04:00
|
|
|
|
using PolyclinicContracts.SearchModels;
|
2024-05-23 14:58:59 +04:00
|
|
|
|
using PolyclinicContracts.ViewModels;
|
|
|
|
|
using PolyclinicWebAppImplementer.Models;
|
|
|
|
|
|
|
|
|
|
namespace PolyclinicWebAppImplementer.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class DiagnosesController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<DiagnosesController> _logger;
|
|
|
|
|
private readonly IDiagnoseLogic _diagnoseLogic;
|
2024-05-26 13:03:03 +04:00
|
|
|
|
|
2024-05-23 14:58:59 +04:00
|
|
|
|
public DiagnosesController(ILogger<DiagnosesController> logger, IDiagnoseLogic diagnoseLogic)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_diagnoseLogic = diagnoseLogic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
2024-05-26 13:03:03 +04:00
|
|
|
|
// TODO выводить только пользовательские диагнозы
|
2024-05-26 11:27:12 +04:00
|
|
|
|
List<DiagnoseViewModel> diagnoses = _diagnoseLogic.ReadList();
|
2024-05-26 14:49:08 +04:00
|
|
|
|
ViewData["Title"] = "Список диагнозов";
|
2024-05-26 13:03:03 +04:00
|
|
|
|
return View("DiagnosesList", diagnoses);
|
2024-05-23 14:58:59 +04:00
|
|
|
|
}
|
2024-05-26 11:43:01 +04:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-26 13:03:03 +04:00
|
|
|
|
[HttpPost]
|
2024-05-27 19:21:15 +04:00
|
|
|
|
public IActionResult Add(DiagnoseViewModel model)
|
2024-05-26 11:43:01 +04:00
|
|
|
|
{
|
2024-05-26 13:03:03 +04:00
|
|
|
|
if (HttpContext.Request.Method == "GET")
|
|
|
|
|
{
|
|
|
|
|
ViewData["Title"] = "Новый диагноз";
|
|
|
|
|
return View("DiagnoseForm");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// TODO прописать UserId
|
|
|
|
|
DiagnoseBindingModel diagnose = new DiagnoseBindingModel
|
|
|
|
|
{
|
2024-05-27 19:21:15 +04:00
|
|
|
|
Name = model.Name,
|
|
|
|
|
Comment = model.Comment,
|
|
|
|
|
DateStartDiagnose = model.DateStartDiagnose,
|
|
|
|
|
DateStopDiagnose = model.DateStopDiagnose,
|
2024-05-26 13:03:03 +04:00
|
|
|
|
};
|
|
|
|
|
_diagnoseLogic.Create(diagnose);
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
2024-05-26 11:43:01 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2024-05-26 13:03:03 +04:00
|
|
|
|
[HttpPost]
|
2024-05-27 19:21:15 +04:00
|
|
|
|
public IActionResult Edit(int id, DiagnoseViewModel model)
|
2024-05-26 11:43:01 +04:00
|
|
|
|
{
|
2024-05-26 13:03:03 +04:00
|
|
|
|
if (HttpContext.Request.Method == "GET")
|
|
|
|
|
{
|
|
|
|
|
var obj = _diagnoseLogic.ReadElement(new DiagnoseSearchModel { Id = id });
|
|
|
|
|
ViewData["Title"] = "Редактировать диагноз";
|
|
|
|
|
return View("DiagnoseForm", obj);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DiagnoseBindingModel diagnose = new DiagnoseBindingModel
|
|
|
|
|
{
|
2024-05-27 19:21:15 +04:00
|
|
|
|
Id = model.Id,
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
Comment = model.Comment,
|
|
|
|
|
DateStartDiagnose = model.DateStartDiagnose,
|
|
|
|
|
DateStopDiagnose = model.DateStopDiagnose,
|
2024-05-26 13:03:03 +04:00
|
|
|
|
};
|
|
|
|
|
_diagnoseLogic.Update(diagnose);
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
2024-05-26 11:43:01 +04:00
|
|
|
|
}
|
2024-05-26 14:49:08 +04:00
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public IActionResult Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
var obj = _diagnoseLogic.ReadElement(new DiagnoseSearchModel { Id = id });
|
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
|
|
|
|
_diagnoseLogic.Delete(new DiagnoseBindingModel { Id = obj.Id });
|
|
|
|
|
}
|
|
|
|
|
return RedirectToAction("Index");
|
|
|
|
|
}
|
2024-05-23 14:58:59 +04:00
|
|
|
|
}
|
|
|
|
|
}
|