79 lines
2.6 KiB
C#
79 lines
2.6 KiB
C#
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
using PolyclinicContracts.BindingModels;
|
|||
|
using PolyclinicContracts.BusinessLogicsContracts;
|
|||
|
using PolyclinicContracts.SearchModels;
|
|||
|
using PolyclinicContracts.ViewModels;
|
|||
|
|
|||
|
namespace PolyclinicWebAppImplementer.Controllers
|
|||
|
{
|
|||
|
public class SymptomesController : Controller
|
|||
|
{
|
|||
|
private readonly ISymptomLogic _symptomLogic;
|
|||
|
private readonly IDiagnoseLogic _diagnoseLogic;
|
|||
|
public SymptomesController(ISymptomLogic symptomLogic, IDiagnoseLogic diagnoseLogic)
|
|||
|
{
|
|||
|
_symptomLogic = symptomLogic;
|
|||
|
_diagnoseLogic = diagnoseLogic;
|
|||
|
}
|
|||
|
[HttpGet]
|
|||
|
public IActionResult Index()
|
|||
|
{
|
|||
|
List<SymptomViewModel> symptomes = _symptomLogic.ReadList();
|
|||
|
ViewData["Title"] = "Список симптомов";
|
|||
|
return View("SymptomesList", symptomes);
|
|||
|
}
|
|||
|
[HttpGet]
|
|||
|
[HttpPost]
|
|||
|
public IActionResult Add(SymptomViewModel model)
|
|||
|
{
|
|||
|
if (HttpContext.Request.Method == "GET")
|
|||
|
{
|
|||
|
ViewData["Title"] = "Новый симптом";
|
|||
|
return View("SymptomForm");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SymptomBindingModel symptom = new SymptomBindingModel
|
|||
|
{
|
|||
|
Name = model.Name,
|
|||
|
Comment = model.Comment,
|
|||
|
};
|
|||
|
_symptomLogic.Create(symptom);
|
|||
|
return RedirectToAction("Index");
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpGet]
|
|||
|
[HttpPost]
|
|||
|
public IActionResult Edit(int id, SymptomViewModel model)
|
|||
|
{
|
|||
|
if (HttpContext.Request.Method == "GET")
|
|||
|
{
|
|||
|
var obj = _symptomLogic.ReadElement(new SymptomSearchModel { Id = id });
|
|||
|
ViewData["Title"] = "Редактировать симптом";
|
|||
|
return View("SymptomForm", obj);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
SymptomBindingModel symptom = new SymptomBindingModel
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
Name = model.Name,
|
|||
|
Comment = model.Comment,
|
|||
|
};
|
|||
|
_symptomLogic.Update(symptom);
|
|||
|
return RedirectToAction("Index");
|
|||
|
}
|
|||
|
}
|
|||
|
[HttpPost]
|
|||
|
public IActionResult Delete(int id)
|
|||
|
{
|
|||
|
var obj = _symptomLogic.ReadElement(new SymptomSearchModel { Id = id });
|
|||
|
if (obj != null)
|
|||
|
{
|
|||
|
_symptomLogic.Delete(new SymptomBindingModel { Id = obj.Id });
|
|||
|
}
|
|||
|
return RedirectToAction("Index");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|