доделала круды вроде для обычных сущностей, нужно привязки сделать..

This commit is contained in:
Елена Бакальская 2024-05-28 16:55:59 +04:00
parent abc0bcf254
commit 9c97590f23
7 changed files with 120 additions and 94 deletions

View File

@ -96,10 +96,6 @@ namespace PolyclinicBusinessLogic.BusinessLogics
{
throw new ArgumentNullException("Количество процедур не может быть равно нулю или быть меньше нуля", nameof(model));
}
if (string.IsNullOrEmpty(model.Comment))
{
throw new ArgumentNullException("Нет комментария", nameof(model.Comment));
}
logger.LogInformation("Recipe. Comment:{Comment}. Id: { Id}", model.Comment, model.Id);
}
}

View File

@ -37,7 +37,7 @@ namespace PolyclinicDatabaseImplement.Implements
public RecipeViewModel? GetElement(RecipeSearchModel bindingModel)
{
if (!bindingModel.Id.HasValue || string.IsNullOrEmpty(bindingModel.Comment))
if (!bindingModel.Id.HasValue)
{
return null;
}

View File

@ -46,7 +46,7 @@ namespace PolyclinicDatabaseImplement.Models
CourseId = bindingModel.CourseId,
Procedures = bindingModel.RecipeProcedures.Select(x => new RecipeProcedure
{
Recipe = database.Recipes.First(y => y.Id == x.Key)
Procedure = database.Procedures.First(y => y.Id == x.Key),
}).ToList()
};
}
@ -73,7 +73,7 @@ namespace PolyclinicDatabaseImplement.Models
if (RecipeProcedures != null)
{
// удалили те, которых нет в модели
database.RecipeProcedures.RemoveRange(RecipeProcedures.Where(rec => !bindingModel.RecipeProcedures.ContainsKey(rec.RecipeId)));
database.RecipeProcedures.RemoveRange(RecipeProcedures);
database.SaveChanges();
}
var Procedure = database.Procedures.First(x => x.Id == bindingModel.Id);

View File

@ -4,6 +4,7 @@ using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.SearchModels;
using PolyclinicContracts.ViewModels;
using PolyclinicDataModels.Models;
using PolyclinicWebAppSuretor.Models;
using System.Diagnostics;
@ -16,18 +17,21 @@ namespace PolyclinicWebAppSuretor.Controllers
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)
ISymptomLogic symptomLogic,
ICourseLogic courseLogic)
{
_logger = logger;
_procedureLogic = procedureLogic;
_medicamentLogic = medicamentLogic;
_recipeLogic = recipeLogic;
_symptomLogic = symptomLogic;
_courseLogic = courseLogic;
}
public IActionResult Index()
@ -52,63 +56,79 @@ namespace PolyclinicWebAppSuretor.Controllers
[HttpGet]
[HttpPost]
public IActionResult CreateRecipe(RecipeViewModel model)
public IActionResult CreateRecipe(RecipeModel model, int[] selectedProcedures)
{
ViewBag.Procedures = _procedureLogic.ReadList(null);
ViewBag.Courses = _courseLogic.ReadList(null);
if (HttpContext.Request.Method == "GET")
{
ViewData["Title"] = "Íîâûé ðåöåïò";
return View();
model = new()
{
Procedures = _procedureLogic.ReadList(null).Select(x => (x, false)).ToList()
};
return View("CreateRecipe", model);
}
else
{
// TODO ïðîïèñàòü UserId
var allProcedures = _procedureLogic.ReadList(null);
RecipeBindingModel recipe = new RecipeBindingModel
{
Comment = model.Comment,
CourseId = model.CourseId,
ProceduresCount = model.ProceduresCount,
RecipeProcedures = model.RecipeProcedures
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("Medicaments");
return RedirectToAction("Recipes");
}
}
[HttpGet]
[HttpPost]
public IActionResult EditRecipe(MedicamentViewModel model)
public IActionResult EditRecipe(int id, RecipeModel model, int[] selectedProcedures)
{
if (HttpContext.Request.Method == "GET")
{
var obj = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = model.Id });
ViewData["Title"] = "Ðåäàêòèðîâàòü ïðåïàðàò";
return View("CreateMedicament", obj);
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"] = "Ðåäàêòèðîâàòü ñèìïòîì";
return View("CreateRecipe", model);
}
else
{
MedicamentBindingModel medicament = new MedicamentBindingModel
var allProcedures = _procedureLogic.ReadList(null);
RecipeBindingModel recipe = new RecipeBindingModel
{
Id = model.Id,
Name = model.Name,
Comment = model.Comment ?? string.Empty,
SymptomId = model.SymptomId,
ProcedureId = model.ProcedureId,
Id = id,
ProceduresCount = model.RecipeViewModel.ProceduresCount,
Comment = model.RecipeViewModel.Comment,
RecipeProcedures = selectedProcedures
.ToDictionary(
x => x,
x => allProcedures.Where(y => y.Id == x) as IProcedureModel
)
};
_medicamentLogic.Update(medicament);
return RedirectToAction("Medicaments");
_recipeLogic.Update(recipe);
return RedirectToAction("Recipes");
}
}
[HttpPost]
public IActionResult DeleteRecipe(int id)
{
var obj = _medicamentLogic.ReadElement(new MedicamentSearchModel { Id = id });
var obj = _recipeLogic.ReadElement(new RecipeSearchModel { Id = id });
if (obj != null)
{
_medicamentLogic.Delete(new MedicamentBindingModel { Id = obj.Id });
_recipeLogic.Delete(new RecipeBindingModel { Id = obj.Id });
}
return RedirectToAction("Medicaments");
return RedirectToAction("Recipes");
}
public IActionResult Medicaments()

View File

@ -0,0 +1,10 @@
using PolyclinicContracts.ViewModels;
namespace PolyclinicWebAppSuretor.Models
{
public class RecipeModel
{
public RecipeViewModel? RecipeViewModel { get; set; }
public List<(ProcedureViewModel procedure, bool IsChecked)> Procedures { get; set; } = new();
}
}

View File

@ -1,8 +1,6 @@
@using PolyclinicContracts.ViewModels
@model RecipeViewModel
@{
@model RecipeModel
}
<div class="text-center mt-3 mb-3">
<h2 class="display-4">@ViewData["Title"]</h2>
</div>
@ -15,65 +13,60 @@
<h3 class="col-3">
Количество процедур:
</h3>
<input class="col-6" type="text" style="width: 45vh" asp-for="ProceduresCount" />
<input class="col-6" type="text" style="width: 45vh" asp-for="RecipeViewModel.ProceduresCount" />
</div>
<div class="d-flex flex-row mb-5 flex-row justify-content-between align-items-center">
<h3 class="col-3">
Комментарий:
</h3>
<textarea class="col-6" id="comment" name="comment" style="width: 45vh" asp-for="Comment">
<textarea class="col-6" style="width: 45vh" asp-for="RecipeViewModel.Comment">
</textarea>
</div>
<div class="d-flex flex-row mb-5 justify-content-between align-items-center">
<div class="d-flex flex-row mb-5 flex-row justify-content-between align-items-center">
<h3 class="col-3">
Выбор процедуры:
Курс (номер):
</h3>
<select id="procedureId" name="procedureId" style="width: 45vh">
<option value="">Выберите процедуру/ы</option>
@foreach (var item in ViewBag.Procedures)
<select id="courseId" style="width: 45vh" asp-for="RecipeViewModel.CourseId">
<option value="">Выберите номер курса</option>
@foreach (var course in ViewBag.Courses)
{
<option value="@item.Id">@item.Name</option>
<option value="@course.Id">@course.PillsPerDay</option>
}
</select>
</div>
</div>
<div class="proc-list d-flex flex-column overflow-auto" style="max-height: 45vh">
<table class="table-recipe-create table">
<thead>
<tr>
<th>
Выбранное из процедур:
</th>
</tr>
</thead>
<tbody>
@foreach (var item in ViewBag.Procedures)
<div class="d-flex flex-row mb-5 justify-content-between align-items-center overflow-auto" style="max-height: 20vh">
<h3 class="col-3">
Выбор процедуры:
</h3>
<label value="">Выберите процедуру/ы</label>
<ol>
@foreach (var item in Model.Procedures)
{
<tr>
<td>Процедура № @item.Id @item.Name</td>
<td>
<svg class="bi-cart-delete" viewBox="0 0 154 164" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M44.5 123C4.99995 119.5 -11.8431 56.4293 24 19.5C40.5 2.50001 72.5 -5.5 101.5 27.5L115.5 14.5" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
<path d="M65.2123 159.963L56 60.0001C88.0236 76.3307 119.521 77.4194 149 60.0001C141.63 142.346 140.08 160.953 140.226 159.963H65.2123Z" stroke="#D10000" stroke-width="8" />
<path d="M121 36L101.582 55L75 31" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
</svg>
</td>
</tr>
<li>
@if (item.IsChecked)
{
<input type="checkbox" id="procedure-@item.procedure.Id" name="selectedProcedures" value="@item.procedure.Id" checked />
}
else
{
<input type="checkbox" id="procedure-@item.procedure.Id" name="selectedProcedures" value="@item.procedure.Id" />
}
<label for="procedure-@item.procedure.Id">@item.procedure.Name</label>
</li>
}
</tbody>
</table>
</ol>
</div>
</div>
<div class="d-flex flex-column mb-5 mt-5">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Сохранить" class="button-save-recipe btn" asp-action="Recipes" />
<input type="submit" value="Сохранить" class="button-save-recipe btn" />
</div>
</div>
</form>

View File

@ -30,6 +30,9 @@
<th>
Количество процедур
</th>
<th>
Номер курса
</th>
<th>
Редактировать
</th>
@ -41,28 +44,32 @@
<tbody>
@foreach (var item in Model)
{
<td>@item.Id</td>
<td>@item.Comment</td>
<td>@item.ProceduresCount</td>
<td>
<a asp-action="CreateRecipe" asp-route-id="@item.Id">
<svg class="bi-edit-pen" viewBox="0 0 127 127" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M105.5 26L37 114.5C34.5 117 16.3 121.7 7.5 122.5C79.1 34.1 101 5.5 102 4C104.833 4.5 119.3 14.6 122.5 21C105 44 98.5 55 111.5 58.5" stroke="#008315" stroke-width="6" stroke-linecap="round" />
</svg>
</a>
</td>
<td>
<form method="post" asp-route-id="@item.Id">
<button class="btn" type="submit">
<svg class="bi-cart-delete" viewBox="0 0 154 164" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M44.5 123C4.99995 119.5 -11.8431 56.4293 24 19.5C40.5 2.50001 72.5 -5.5 101.5 27.5L115.5 14.5" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
<path d="M65.2123 159.963L56 60.0001C88.0236 76.3307 119.521 77.4194 149 60.0001C141.63 142.346 140.08 160.953 140.226 159.963H65.2123Z" stroke="#D10000" stroke-width="8" />
<path d="M121 36L101.582 55L75 31" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
</svg>
</button>
</form>
<tr>
<td>@item.Id</td>
<td>@item.Comment</td>
<td>@item.ProceduresCount</td
<td>@item.CourseId</td>
<td>
<a asp-action="EditRecipe" asp-route-id="@item.Id">
<svg class="bi-edit-pen" viewBox="0 0 127 127" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M105.5 26L37 114.5C34.5 117 16.3 121.7 7.5 122.5C79.1 34.1 101 5.5 102 4C104.833 4.5 119.3 14.6 122.5 21C105 44 98.5 55 111.5 58.5" stroke="#008315" stroke-width="6" stroke-linecap="round" />
</svg>
</a>
</td>
<td>
<form method="post" asp-route-id="@item.Id" asp-action="DeleteRecipe">
<button class="btn" type="submit">
<svg class="bi-cart-delete" viewBox="0 0 154 164" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M44.5 123C4.99995 119.5 -11.8431 56.4293 24 19.5C40.5 2.50001 72.5 -5.5 101.5 27.5L115.5 14.5" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
<path d="M65.2123 159.963L56 60.0001C88.0236 76.3307 119.521 77.4194 149 60.0001C141.63 142.346 140.08 160.953 140.226 159.963H65.2123Z" stroke="#D10000" stroke-width="8" />
<path d="M121 36L101.582 55L75 31" stroke="#D10000" stroke-width="8" stroke-linecap="round" />
</svg>
</button>
</form>
</td>
</tr>
</td>
}
</tbody>