using Microsoft.AspNetCore.Mvc; using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.SearchModels; using PolyclinicContracts.ViewModels; using PolyclinicWebAppImplementer.Models; namespace PolyclinicWebAppImplementer.Controllers { public class DiagnosesController : Controller { private readonly ILogger _logger; private readonly IDiagnoseLogic _diagnoseLogic; public DiagnosesController(ILogger logger, IDiagnoseLogic diagnoseLogic) { _logger = logger; _diagnoseLogic = diagnoseLogic; } [HttpGet] public IActionResult Index() { // TODO выводить только пользовательские диагнозы List diagnoses = _diagnoseLogic.ReadList(); return View("DiagnosesList", diagnoses); } [HttpGet] [HttpPost] public IActionResult Add(int id, string name, string comment, DateTime dateStart, DateTime dateStop) { if (HttpContext.Request.Method == "GET") { ViewData["Title"] = "Новый диагноз"; return View("DiagnoseForm"); } else { // TODO прописать UserId DiagnoseBindingModel diagnose = new DiagnoseBindingModel { Id = id, Name = name, Comment = comment, DateStartDiagnose = dateStart, DateStopDiagnose = dateStop, }; _diagnoseLogic.Create(diagnose); return RedirectToAction("Index"); } } [HttpGet] [HttpPost] public IActionResult Edit(int id, string name, string comment, DateTime dateStart, DateTime dateStop) { if (HttpContext.Request.Method == "GET") { var obj = _diagnoseLogic.ReadElement(new DiagnoseSearchModel { Id = id }); ViewData["Title"] = "Редактировать диагноз"; return View("DiagnoseForm", obj); } else { DiagnoseBindingModel diagnose = new DiagnoseBindingModel { Id = id, Name = name, Comment = comment, DateStartDiagnose = dateStart, DateStopDiagnose = dateStop, }; _diagnoseLogic.Update(diagnose); return RedirectToAction("Index"); } } } }