From 7ed2d7045581f4db35e4874b690faa76e67f3b65 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Tue, 28 May 2024 13:55:03 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BA=D1=80=D1=83=D0=B4=20=D0=B4=D0=BB=D1=8F=20=D1=81?= =?UTF-8?q?=D0=B8=D0=BC=D0=BF=D1=82=D0=BE=D0=BC=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/SymptomLogic.cs | 2 +- .../SearchModels/SymptomSearchModel.cs | 2 +- .../Implements/CourseStorage.cs | 7 +-- .../Implements/SymptomStorage.cs | 36 +++++++++++----- .../Models/Symptom.cs | 9 ++-- .../Controllers/SymptomesController.cs | 36 ++++++++++++---- .../Models/SymptomFormModel.cs | 3 +- .../Views/Diagnoses/DiagnoseForm.cshtml | 16 +++---- .../Views/Symptomes/SymptomForm.cshtml | 43 ++++++------------- 9 files changed, 84 insertions(+), 70 deletions(-) diff --git a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs index a1dea88..f52adc7 100644 --- a/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs +++ b/Polyclinic/PolyclinicBusinessLogic/BusinessLogics/SymptomLogic.cs @@ -73,7 +73,7 @@ namespace PolyclinicBusinessLogic.BusinessLogics public bool Update(SymptomBindingModel model) { - CheckModel(model); + CheckModel(model, false); if (_symptomStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); diff --git a/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs b/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs index 8131037..d3ee845 100644 --- a/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs +++ b/Polyclinic/PolyclinicContracts/SearchModels/SymptomSearchModel.cs @@ -3,6 +3,6 @@ public class SymptomSearchModel { public int? Id { get; set; } - public string?Name { get; set; } + public string? Name { get; set; } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs index fccc716..e49cdd8 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs @@ -31,12 +31,9 @@ namespace PolyclinicDatabaseImplement.Implements public List GetFilteredList(CourseSearchModel model) { var elements = GetFullList(); - foreach (var prop in model.GetType().GetProperties()) + if (model.Id != null) { - if (model.GetType().GetProperty(prop.Name)?.GetValue(model, null) != null) - { - elements = elements.Where(x => x.GetType().GetProperty(prop.Name)?.GetValue(x, null) == model.GetType().GetProperty(prop.Name)?.GetValue(model, null)).ToList(); - } + elements = elements.Where(x => x.Id == model.Id).ToList(); } return elements; } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs index ce5759d..a532493 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; using PolyclinicContracts.BindingModels; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; @@ -31,12 +32,13 @@ namespace PolyclinicDatabaseImplement.Implements public List GetFilteredList(SymptomSearchModel model) { var elements = GetFullList(); - foreach (var prop in model.GetType().GetProperties()) + if (model.Id != null) { - if (model.GetType().GetProperty(prop.Name)?.GetValue(model, null) != null) - { - elements = elements.Where(x => x.GetType().GetProperty(prop.Name)?.GetValue(x, null) == model.GetType().GetProperty(prop.Name)?.GetValue(model, null)).ToList(); - } + elements = elements.Where(x => x.Id == model.Id).ToList(); + } + if (!model.Name.IsNullOrEmpty()) + { + elements = elements.Where(x => x.Name == model.Name).ToList(); } return elements; } @@ -67,14 +69,26 @@ namespace PolyclinicDatabaseImplement.Implements public SymptomViewModel? Update(SymptomBindingModel model) { using var context = new PolyclinicDatabase(); - var element = context.Symptomes.FirstOrDefault(x => x.Id == model.Id); - if (element == null) + using var transaction = context.Database.BeginTransaction(); + try { - return null; + var element = context.Symptomes.FirstOrDefault(x => x.Id == model.Id); + if (element == null) + { + return null; + } + element.Update(model); + context.SaveChanges(); + element.UpdateDiagnoses(context, model); + transaction.Commit(); + return element.GetViewModel; } - element.Update(model); - context.SaveChanges(); - return element.GetViewModel; + catch (Exception ex) + { + transaction.Rollback(); + throw; + } + } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs index f0c9b51..def1f94 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Symptom.cs @@ -63,19 +63,18 @@ namespace PolyclinicDatabaseImplement.Models public void UpdateDiagnoses(PolyclinicDatabase context, SymptomBindingModel model) { var symptomDiagnoses = context.SymptomDiagnoses.Where(rec => rec.SymptomId == model.Id).ToList(); + if (symptomDiagnoses != null && symptomDiagnoses.Count > 0) { - // удалили те, которых нет в модели - context.SymptomDiagnoses.RemoveRange(symptomDiagnoses - .Where(rec => !model.SymptomDiagnoses.ContainsKey(rec.DiagnoseId))); + context.SymptomDiagnoses.RemoveRange(symptomDiagnoses); context.SaveChanges(); } - var course = context.Symptomes.First(x => x.Id == Id); + var symptom = context.Symptomes.First(x => x.Id == model.Id); foreach (var pc in model.SymptomDiagnoses) { context.SymptomDiagnoses.Add(new SymptomDiagnose { - Symptom = course, + Symptom = symptom, Diagnose = context.Diagnoses.First(x => x.Id == pc.Key), }); context.SaveChanges(); diff --git a/Polyclinic/PolyclinicWebAppImplementer/Controllers/SymptomesController.cs b/Polyclinic/PolyclinicWebAppImplementer/Controllers/SymptomesController.cs index 6cf3a23..8578b12 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Controllers/SymptomesController.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Controllers/SymptomesController.cs @@ -3,6 +3,7 @@ using PolyclinicContracts.BindingModels; using PolyclinicContracts.BusinessLogicsContracts; using PolyclinicContracts.SearchModels; using PolyclinicContracts.ViewModels; +using PolyclinicDataModels.Models; using PolyclinicWebAppImplementer.Models; namespace PolyclinicWebAppImplementer.Controllers @@ -25,21 +26,29 @@ namespace PolyclinicWebAppImplementer.Controllers } [HttpGet] [HttpPost] - public IActionResult Add(SymptomFormModel model) + public IActionResult Add(SymptomFormModel model, int[] selectedDiagnoses) { if (HttpContext.Request.Method == "GET") { ViewData["Title"] = "Новый симптом"; - model = new(); - model.AvailableDiagnoses = _diagnoseLogic.ReadList(); + model = new() + { + Diagnoses = _diagnoseLogic.ReadList().Select(x => (x, false)).ToList() + }; return View("SymptomForm", model); } else { + var allDiagnoses = _diagnoseLogic.ReadList(); SymptomBindingModel symptom = new SymptomBindingModel { Name = model.SymptomViewModel.Name, Comment = model.SymptomViewModel.Comment, + SymptomDiagnoses = selectedDiagnoses + .ToDictionary( + x => x, + x => allDiagnoses.Where(y => y.Id == x) as IDiagnoseModel + ) }; _symptomLogic.Create(symptom); return RedirectToAction("Index"); @@ -47,21 +56,32 @@ namespace PolyclinicWebAppImplementer.Controllers } [HttpGet] [HttpPost] - public IActionResult Edit(int id, SymptomViewModel model) + public IActionResult Edit(int id, SymptomFormModel model, int[] selectedDiagnoses) { if (HttpContext.Request.Method == "GET") { var obj = _symptomLogic.ReadElement(new SymptomSearchModel { Id = id }); + model = new() + { + SymptomViewModel = obj, + Diagnoses = _diagnoseLogic.ReadList().Select(x => (x, obj.SymptomDiagnoses.ContainsKey(x.Id))).ToList() + }; ViewData["Title"] = "Редактировать симптом"; - return View("SymptomForm", obj); + return View("SymptomForm", model); } else { + var allDiagnoses = _diagnoseLogic.ReadList(); SymptomBindingModel symptom = new SymptomBindingModel { - Id = model.Id, - Name = model.Name, - Comment = model.Comment, + Id = id, + Name = model.SymptomViewModel.Name, + Comment = model.SymptomViewModel.Comment, + SymptomDiagnoses = selectedDiagnoses + .ToDictionary( + x => x, + x => allDiagnoses.Where(y => y.Id == x) as IDiagnoseModel + ) }; _symptomLogic.Update(symptom); return RedirectToAction("Index"); diff --git a/Polyclinic/PolyclinicWebAppImplementer/Models/SymptomFormModel.cs b/Polyclinic/PolyclinicWebAppImplementer/Models/SymptomFormModel.cs index 58de5b0..3364b2c 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Models/SymptomFormModel.cs +++ b/Polyclinic/PolyclinicWebAppImplementer/Models/SymptomFormModel.cs @@ -5,7 +5,6 @@ namespace PolyclinicWebAppImplementer.Models public class SymptomFormModel { public SymptomViewModel? SymptomViewModel { get; set; } - public List SelectecDiagnoses { get; set; } = new(); - public List AvailableDiagnoses { get; set; } = new(); + public List<(DiagnoseViewModel Diagnose, bool IsChecked)> Diagnoses { get; set; } = new(); } } diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml index d730b29..e786401 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Diagnoses/DiagnoseForm.cshtml @@ -4,20 +4,20 @@
-
Название:
-
+
Название:
+
-
Коментарий:
-
+
Коментарий:
+
-
Начало:
-
+
Начало:
+
-
Конец:
-
+
Конец:
+
diff --git a/Polyclinic/PolyclinicWebAppImplementer/Views/Symptomes/SymptomForm.cshtml b/Polyclinic/PolyclinicWebAppImplementer/Views/Symptomes/SymptomForm.cshtml index 2e6b4e8..aa4b38e 100644 --- a/Polyclinic/PolyclinicWebAppImplementer/Views/Symptomes/SymptomForm.cshtml +++ b/Polyclinic/PolyclinicWebAppImplementer/Views/Symptomes/SymptomForm.cshtml @@ -4,42 +4,27 @@
Название:
-
+
Коментарий:
-
-
-
Болезни
- - -
-
    - @{ - int count = 7; - for (int i = 0; i < count; i++) - { -
  1. - - - - - - Выбранная болезнь -
  2. - } + @foreach (var item in Model.Diagnoses) + { +
  3. + @if (item.IsChecked) + { + + } + else + { + + } + +
  4. }
From 549379a5882288196f5367cac9b943fbf1fe6a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Tue, 28 May 2024 15:03:28 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D1=87=D1=82=D0=BE-=D1=82=D0=BE=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=B4=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BB=D0=B0=20=D0=B2=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=86=D0=B5=D0=B4=D1=83=D1=80=D0=B0=D1=85=20=D0=B8=20=D1=80?= =?UTF-8?q?=D0=B5=D1=86=D0=B5=D0=BF=D1=82=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/ReportBindingModel.cs | 8 +------- Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs | 1 + .../PolyclinicWebAppSuretor/Controllers/HomeController.cs | 2 +- .../Views/Home/CreateRecipe.cshtml | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs b/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs index 76607a0..e5f4907 100644 --- a/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs +++ b/Polyclinic/PolyclinicContracts/BindingModels/ReportBindingModel.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PolyclinicContracts.BindingModels +namespace PolyclinicContracts.BindingModels { public class ReportBindingModel { diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs index d8b2ffc..6bb6636 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Recipe.cs @@ -84,6 +84,7 @@ namespace PolyclinicDatabaseImplement.Models Procedure = Procedure, Recipe = database.Recipes.First(x => x.Id == pc.Key) }); + database.SaveChanges(); } _recipeProcedures = null; } diff --git a/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs b/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs index 60fe2f9..c695373 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs +++ b/Polyclinic/PolyclinicWebAppSuretor/Controllers/HomeController.cs @@ -55,7 +55,7 @@ namespace PolyclinicWebAppSuretor.Controllers public IActionResult CreateRecipe(RecipeViewModel model) { ViewBag.Procedures = _procedureLogic.ReadList(null); - ViewBag.RecipeProcedures = _recipeLogic. + //ViewBag.RecipeProcedures = _recipeLogic. if (HttpContext.Request.Method == "GET") { ViewData["Title"] = " "; diff --git a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/CreateRecipe.cshtml b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/CreateRecipe.cshtml index 69434ab..d7fd636 100644 --- a/Polyclinic/PolyclinicWebAppSuretor/Views/Home/CreateRecipe.cshtml +++ b/Polyclinic/PolyclinicWebAppSuretor/Views/Home/CreateRecipe.cshtml @@ -32,7 +32,7 @@

Выбор процедуры:

- @foreach (var item in ViewBag.Procedures) { @@ -52,7 +52,7 @@ - @foreach (var item in ViewBag.RecipeProcedures) + @foreach (var item in ViewBag.Procedures) { Процедура № @item.Id @item.Name