diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs index a81b80b..dabca05 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs @@ -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) diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/RecipeController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/RecipeController.cs new file mode 100644 index 0000000..7528aaf --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/RecipeController.cs @@ -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"); + } + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/RecipeLinkCourseModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/RecipeLinkCourseModel.cs new file mode 100644 index 0000000..b36d039 --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/RecipeLinkCourseModel.cs @@ -0,0 +1,15 @@ +using PolyclinicContracts.ViewModels; + +namespace PolyclinicWebAppImplementer.Models +{ + public class RecipeLinkCourseModel + { + public List Recipes { get; set; } = new(); + public List 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(); + } +} diff --git a/Polyclinic/PolyclinicWebAppImplementer/SiteMenuItems.cs b/Polyclinic/PolyclinicWebAppImplementer/SiteMenuItems.cs index 4d1e0b3..56de383 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/SiteMenuItems.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/SiteMenuItems.cs @@ -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); diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/AddRecipeToCourse.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Home/AddRecipeToCourse.cshtml deleted file mode 100644 index db4c20e..0000000 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Home/AddRecipeToCourse.cshtml +++ /dev/null @@ -1,41 +0,0 @@ -@{ - ViewBag.SelectedSiteMenuItem = SiteMenuItems.AddRecipeToCourse; -} -

Привязка рецепта к курсу

-
-
-
-
Рецепт
- -
-
-
-
-
Курс
- -
-
-
-
- -
-
-
\ No newline at end of file diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Recipe/LinkCourse.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Recipe/LinkCourse.cshtml new file mode 100644 index 0000000..ccfbe9a --- /dev/null +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Recipe/LinkCourse.cshtml @@ -0,0 +1,67 @@ +@model RecipeLinkCourseModel +@{ + ViewBag.SelectedSiteMenuItem = SiteMenuItems.AddRecipeToCourse; +} +

Привязка рецепта к курсу

+
+
+
+
+
Рецепт
+ +
+
+
+
+
Курс
+ +
+
+
+
+ +
+
+
+
+

Привязанные рецепты

+ + + + + + + @foreach (var item in Model.LinkedRecipes) + { + + + + + + } +
РецептКурс
#@item.Recipe.Id @item.Recipe.Comment#@item.Course.Id @item.Course.Comment +
+ +
+
+
+