Работает привязка\отвязка курсов к рецептам в исполнителе

This commit is contained in:
Никита Потапов 2024-05-29 18:04:11 +04:00
parent 1c68c684c6
commit 00dbb2356c
6 changed files with 159 additions and 42 deletions

View File

@ -68,6 +68,10 @@ namespace PolyclinicDatabaseImplement.Models
public void UpdateProcedures(PolyclinicDatabase database, RecipeBindingModel bindingModel)
{
if (database.Procedures.Count() == 0)
{
return;
}
var RecipeProcedures = database.RecipeProcedures.Where(x => x.ProcedureId == bindingModel.Id).ToList();
if (RecipeProcedures != null)

View File

@ -0,0 +1,72 @@
using Microsoft.AspNetCore.Mvc;
using PolyclinicBusinessLogic.BusinessLogics;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.BusinessLogicsContracts;
using PolyclinicContracts.SearchModels;
using PolyclinicWebAppImplementer.Models;
namespace PolyclinicWebAppImplementer.Controllers
{
public class RecipeController : Controller
{
private readonly IRecipeLogic _recipeLogic;
private readonly ICourseLogic _courseLogic;
public RecipeController(IRecipeLogic recipeLogic, ICourseLogic courseLogic)
{
_recipeLogic = recipeLogic;
_courseLogic = courseLogic;
}
[HttpGet]
[HttpPost]
public IActionResult LinkCourse(RecipeLinkCourseModel model)
{
var recipes = _recipeLogic.ReadList();
var courses = _courseLogic.ReadList();
var linkedRecipes = recipes
.Where(x => x.CourseId != null)
.Select(x => (x, _courseLogic.ReadElement(new CourseSearchModel { Id = x.CourseId }))).ToList();
if (HttpContext.Request.Method == "GET")
{
model = new()
{
Recipes = recipes,
Courses = courses,
LinkedRecipes = linkedRecipes
};
return View(model);
}
else
{
var recipe = _recipeLogic.ReadElement(new RecipeSearchModel { Id = model.RecipeId });
var recipeBindingModel = new RecipeBindingModel
{
Id = recipe.Id,
ProceduresCount = recipe.ProceduresCount,
Comment = recipe.Comment,
RecipeProcedures = recipe.RecipeProcedures,
CourseId = model.CourseId
};
_recipeLogic.Update(recipeBindingModel);
return RedirectToAction("LinkCourse");
}
}
[HttpPost]
public IActionResult UnLinkCourse(int id)
{
var recipe = _recipeLogic.ReadElement(new RecipeSearchModel { Id = id });
var recipeBindingModel = new RecipeBindingModel
{
Id = recipe.Id,
ProceduresCount = recipe.ProceduresCount,
Comment = recipe.Comment,
RecipeProcedures = recipe.RecipeProcedures
};
_recipeLogic.Update(recipeBindingModel);
return RedirectToAction("LinkCourse");
}
}
}

View File

@ -0,0 +1,15 @@
using PolyclinicContracts.ViewModels;
namespace PolyclinicWebAppImplementer.Models
{
public class RecipeLinkCourseModel
{
public List<RecipeViewModel> Recipes { get; set; } = new();
public List<CourseViewModel> Courses { get; set; } = new();
public int? RecipeId { get; set; }
public int? CourseId { get; set; }
public RecipeViewModel? Recipe { get; set; }
public CourseViewModel? Course { get; set; }
public List<(RecipeViewModel Recipe, CourseViewModel Course)> LinkedRecipes { get; set; } = new();
}
}

View File

@ -9,7 +9,7 @@
public static (string Controller, string Action, string Title, PageVisible Visible) Login = ("User", "Login", "Вход", PageVisible.AllowOnlyNotAuthorized);
public static (string Controller, string Action, string Title, PageVisible Visible) Register = ("User", "Register", "Регистрация", PageVisible.AllowOnlyNotAuthorized);
public static (string Controller, string Action, string Title, PageVisible Visible) Privacy = ("User", "Privacy", "Личный кабинет", PageVisible.AllowOnlyAuthorized);
public static (string Controller, string Action, string Title, PageVisible Visible) AddRecipeToCourse = ("Home", "AddRecipeToCourse", "Привязка рецепта", PageVisible.AllowOnlyAuthorized);
public static (string Controller, string Action, string Title, PageVisible Visible) AddRecipeToCourse = ("Recipe", "LinkCourse", "Привязка рецептов", PageVisible.AllowOnlyAuthorized);
public static (string Controller, string Action, string Title, PageVisible Visible) MedicamentsByDiagnoses = ("Home", "MedicamentsByDiagnoses", "Лекарства по болезням", PageVisible.AllowOnlyAuthorized);
public static (string Controller, string Action, string Title, PageVisible Visible) DiagnosesReport = ("Home", "DiagnosesReport", "Отчет по болезням", PageVisible.AllowOnlyAuthorized);

View File

@ -1,41 +0,0 @@
@{
ViewBag.SelectedSiteMenuItem = SiteMenuItems.AddRecipeToCourse;
}
<h4>Привязка рецепта к курсу</h4>
<form id="addrecipetocourse" method="post">
<div class="row mb-2">
<div class="col-3 d-flex align-content-center">
<h5 class="me-2">Рецепт</h5>
<select id="recipeId" name="recipeId" class="me-2">
<option value="">Выберите рецепт</option>
@{
for (int i = 0; i < 10; i++)
{
<option value="@i">Рецепт оууеее @i</option>
}
}
</select>
</div>
</div>
<div class="row mb-2">
<div class="col-3 d-flex align-content-center">
<h5 class="me-2">Курс</h5>
<select id="courseId" name="courseId" class="me-2">
<option value="">Выберите курс</option>
@{
for (int i = 0; i < 10; i++)
{
<option value="@i">Какой то курс @i</option>
}
}
</select>
</div>
</div>
<div class="row mb-2">
<div class="col-3">
<button class="btn btn-primary" type="submit">
Привязать
</button>
</div>
</div>
</form>

View File

@ -0,0 +1,67 @@
@model RecipeLinkCourseModel
@{
ViewBag.SelectedSiteMenuItem = SiteMenuItems.AddRecipeToCourse;
}
<h4>Привязка рецепта к курсу</h4>
<div class="row">
<form method="post" class="col">
<div class="row mb-2">
<div class="col-3 d-flex align-content-center">
<h5 class="me-2">Рецепт</h5>
<select required asp-for="@Model.RecipeId" class="me-2">
<option value="">Выберите рецепт</option>
@foreach (var item in Model.Recipes)
{
@if (item.CourseId == null)
{
<option value="@item.Id">#@item.Id @item.Comment</option>
}
}
</select>
</div>
</div>
<div class="row mb-2">
<div class="col-3 d-flex align-content-center">
<h5 class="me-2">Курс</h5>
<select required asp-for="@Model.CourseId" class="me-2">
<option value="">Выберите курс</option>
@foreach (var item in Model.Courses)
{
<option value="@item.Id">#@item.Id @item.Comment</option>
}
</select>
</div>
</div>
<div class="row mb-2">
<div class="col-3">
<button class="btn btn-primary" type="submit">
Привязать
</button>
</div>
</div>
</form>
<div class="col">
<h4>Привязанные рецепты</h4>
<table>
<tr>
<th>Рецепт</th>
<th>Курс</th>
<th></th>
</tr>
@foreach (var item in Model.LinkedRecipes)
{
<tr>
<td>#@item.Recipe.Id @item.Recipe.Comment</td>
<td>#@item.Course.Id @item.Course.Comment</td>
<td>
<form method="post" asp-action="UnLinkCourse" asp-route-id="@item.Recipe.Id">
<button class="btn btn-danger btm-sm" type="submit">
Отвязать
</button>
</form>
</td>
</tr>
}
</table>
</div>
</div>