поправила привязку симптомов и лекарств. теперь она хотя бы есть :/

This commit is contained in:
Елена Бакальская 2024-05-30 09:36:16 +04:00
parent a7b8d36892
commit af1c7a376a
5 changed files with 96 additions and 17 deletions

View File

@ -84,7 +84,7 @@ namespace PolyclinicWebAppImplementer.Controllers
CourseViewModel = obj,
Diagnoses = _diagnoseLogic.ReadList().Select(x => (x, obj.CourseDiagnoses.ContainsKey(x.Id))).ToList()
};
ViewData["Title"] = "Редактировать симптом";
ViewData["Title"] = "Редактировать курс";
return View("CourseForm", model);
}
else

View File

@ -504,20 +504,7 @@ namespace PolyclinicWebAppSuretor.Controllers
return RedirectToAction("Procedures");
}
public IActionResult AddSymptomToMedicament(AddSymptomToMedicamentModel model)
{
var currentUser = LoginManager.LogginedUser;
if (currentUser == null)
{
return RedirectToAction("Login", "Home");
}
model = new()
{
Medicaments = _medicamentLogic.ReadList(null),
Symptoms = _symptomLogic.ReadList(null)
};
return View(model);
}
public IActionResult ListCoursesByProcedures()
{
@ -657,6 +644,70 @@ namespace PolyclinicWebAppSuretor.Controllers
}
}
[HttpGet]
[HttpPost]
public IActionResult AddSymptomToMedicament(AddSymptomToMedicamentModel model)
{
var currentUser = LoginManager.LogginedUser;
if (currentUser == null)
{
return RedirectToAction("Login", "Home");
}
var medicaments = _medicamentLogic.ReadList(null);
var symptomes = _symptomLogic.ReadList();
var linkedMedicaments = medicaments
.Where(x => x.SymptomId != null)
.Select(x => (x, _symptomLogic.ReadElement(new SymptomSearchModel { Id = x.SymptomId }))).ToList();
if (HttpContext.Request.Method == "GET")
{
model = new()
{
Medicaments = medicaments,
Symptoms = symptomes,
LinkedMedicaments = linkedMedicaments
};
return View(model);
}
else
{
var medicament = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = model.MedicamentId });
var medicamentBindingModel = new MedicamentBindingModel
{
Id = medicament.Id,
Name = medicament.Name,
Comment = medicament.Comment,
SymptomId = model.SymptomId,
ProcedureId = medicament.ProcedureId
};
_medicamentLogic.Update(medicamentBindingModel);
return RedirectToAction("AddSymptomToMedicament");
}
}
[HttpPost]
public IActionResult UnLinkCourse(int id)
{
var currentUser = LoginManager.LogginedUser;
if (currentUser == null)
{
return RedirectToAction("Login", "Home");
}
var medicament = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = id });
var medicamentBindingModel = new MedicamentBindingModel
{
Id = medicament.Id,
Name = medicament.Name,
Comment = medicament.Comment,
//SymptomId = null,
ProcedureId = medicament.ProcedureId
};
_medicamentLogic.Update(medicamentBindingModel);
return RedirectToAction("AddSymptomToMedicament");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{

View File

@ -6,5 +6,8 @@ namespace PolyclinicWebAppSuretor.Models
{
public List<MedicamentViewModel> Medicaments { get; set; } = new();
public List<SymptomViewModel> Symptoms { get; set; } = new();
public int? MedicamentId { get; set; }
public int? SymptomId { get; set;}
public List<(MedicamentViewModel medicament, SymptomViewModel symptom)> LinkedMedicaments { get; set; } = new();
}
}

View File

@ -43,4 +43,29 @@
</button>
</div>
</div>
</form>
</form>
<div class="col">
<h4>Привязанные симптомы</h4>
<table>
<tr>
<th>Лекарство</th>
<th>Симптом</th>
<th></th>
</tr>
@foreach (var item in Model.LinkedMedicaments)
{
<tr>
<td>#@item.medicament.Id @item.medicament.Name</td>
<td>#@item.symptom.Id @item.symptom.Name</td>
<td>
<form method="post" asp-action="UnLinkCourse" asp-route-id="@item.medicament.Id">
<button class="btn btn-danger btm-sm" type="submit">
Отвязать
</button>
</form>
</td>
</tr>
}
</table>
</div>

View File

@ -55,7 +55,7 @@
{
<div class="d-flex align-items-center">
@Html.RouteLink(LoginManager.LogginedUser.FIO, new { controller = "Home", action = "Privacy" }, new { @title = "Личный кабинет" })
<form class="ms-3" method="post" asp-action="Logout" asp-controller="User">
<form class="ms-3" method="post" asp-action="Logout" asp-controller="Home">
<button class="btn btn-secondary" type="submit">Выйти</button>
</form>
</div>