From 5e0c6f97a3195c074768bb836545bae1af866962 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 29 Apr 2024 21:47:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8?= =?UTF-8?q?=D1=89=D0=B0=20=D0=BA=D1=83=D1=80=D1=81=D0=B0,=20=D0=B4=D0=B8?= =?UTF-8?q?=D0=B0=D0=B3=D0=BD=D0=BE=D0=B7=D0=B0=20=D0=B8=20=D1=81=D0=B8?= =?UTF-8?q?=D0=BC=D0=BF=D1=82=D0=BE=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/CourseStorage.cs | 55 ++++++++++++++++--- .../Implements/DiagnoseStorage.cs | 53 +++++++++++++++--- .../Implements/SymptomStorage.cs | 54 +++++++++++++++--- .../Models/Course.cs | 1 + 4 files changed, 142 insertions(+), 21 deletions(-) diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs index e7605f3..80ba25e 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/CourseStorage.cs @@ -1,7 +1,10 @@ -using PolyclinicContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using PolyclinicContracts.BindingModels; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; using PolyclinicContracts.ViewModels; +using PolyclinicDatabaseImplement.Models; +using SecuritySystemDatabaseImplement; namespace PolyclinicDatabaseImplement.Implements { @@ -9,32 +12,70 @@ namespace PolyclinicDatabaseImplement.Implements { public CourseViewModel? Delete(CourseBindingModel model) { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + var element = context.Courses.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Courses.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; } public CourseViewModel? GetElement(CourseSearchModel model) { - throw new NotImplementedException(); + return GetFilteredList(model).FirstOrDefault(); } public List GetFilteredList(CourseSearchModel model) { - throw new NotImplementedException(); + var elements = GetFullList(); + foreach (var prop in model.GetType().GetProperties()) + { + 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(); + } + } + return elements; } public List GetFullList() { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + return context.Courses + .Include(x => x.Recipe) + .Include(x => x.Diagnoses) + .ThenInclude(x => x.Diagnose) + .Select(x => x.GetViewModel) + .ToList(); } public CourseViewModel? Insert(CourseBindingModel model) { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + var element = Course.Create(context, model); + if (element == null) + { + return null; + } + context.Courses.Add(element); + context.SaveChanges(); + return element.GetViewModel; } public CourseViewModel? Update(CourseBindingModel model) { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + var element = context.Courses.FirstOrDefault(x => x.Id == model.Id); + if (element == null) + { + return null; + } + element.Update(model); + context.SaveChanges(); + return element.GetViewModel; } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/DiagnoseStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/DiagnoseStorage.cs index b49c1cb..9baf039 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/DiagnoseStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/DiagnoseStorage.cs @@ -1,7 +1,10 @@ -using PolyclinicContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using PolyclinicContracts.BindingModels; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; using PolyclinicContracts.ViewModels; +using PolyclinicDatabaseImplement.Models; +using SecuritySystemDatabaseImplement; namespace PolyclinicDatabaseImplement.Implements { @@ -9,32 +12,68 @@ namespace PolyclinicDatabaseImplement.Implements { public DiagnoseViewModel? Delete(DiagnoseBindingModel model) { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + var element = context.Diagnoses.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Diagnoses.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; } public DiagnoseViewModel? GetElement(DiagnoseSearchModel model) { - throw new NotImplementedException(); + return GetFilteredList(model).FirstOrDefault(); } public List GetFilteredList(DiagnoseSearchModel model) { - throw new NotImplementedException(); + var elements = GetFullList(); + foreach (var prop in model.GetType().GetProperties()) + { + 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(); + } + } + return elements; } public List GetFullList() { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + return context.Diagnoses + .Include(x => x.User) + .Select(x => x.GetViewModel) + .ToList(); } public DiagnoseViewModel? Insert(DiagnoseBindingModel model) { - throw new NotImplementedException(); + var element = Diagnose.Create(model); + if (element == null) + { + return null; + } + using var context = new PolyclinicDatabase(); + context.Diagnoses.Add(element); + context.SaveChanges(); + return element.GetViewModel; } public DiagnoseViewModel? Update(DiagnoseBindingModel model) { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + var element = context.Diagnoses.FirstOrDefault(x => x.Id == model.Id); + if (element == null) + { + return null; + } + element.Update(model); + context.SaveChanges(); + return element.GetViewModel; } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs index 8c461a8..ce5759d 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/SymptomStorage.cs @@ -1,7 +1,10 @@ -using PolyclinicContracts.BindingModels; +using Microsoft.EntityFrameworkCore; +using PolyclinicContracts.BindingModels; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; using PolyclinicContracts.ViewModels; +using PolyclinicDatabaseImplement.Models; +using SecuritySystemDatabaseImplement; namespace PolyclinicDatabaseImplement.Implements { @@ -9,32 +12,69 @@ namespace PolyclinicDatabaseImplement.Implements { public SymptomViewModel? Delete(SymptomBindingModel model) { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + var element = context.Symptomes.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Symptomes.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; } public SymptomViewModel? GetElement(SymptomSearchModel model) { - throw new NotImplementedException(); + return GetFilteredList(model).FirstOrDefault(); } public List GetFilteredList(SymptomSearchModel model) { - throw new NotImplementedException(); + var elements = GetFullList(); + foreach (var prop in model.GetType().GetProperties()) + { + 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(); + } + } + return elements; } public List GetFullList() { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + return context.Symptomes + .Include(x => x.Diagnoses) + .ThenInclude(x => x.Diagnose) + .Select(x => x.GetViewModel) + .ToList(); } public SymptomViewModel? Insert(SymptomBindingModel model) { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + var element = Symptom.Create(context, model); + if (element == null) + { + return null; + } + context.Symptomes.Add(element); + context.SaveChanges(); + return element.GetViewModel; } public SymptomViewModel? Update(SymptomBindingModel model) { - throw new NotImplementedException(); + using var context = new PolyclinicDatabase(); + var element = context.Symptomes.FirstOrDefault(x => x.Id == model.Id); + if (element == null) + { + return null; + } + element.Update(model); + context.SaveChanges(); + return element.GetViewModel; } } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs b/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs index 3f32268..ec7c262 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Models/Course.cs @@ -21,6 +21,7 @@ namespace PolyclinicDatabaseImplement.Models [ForeignKey("CourseId")] public virtual List Diagnoses { get; set; } = new(); private Dictionary? _courseDiagnoses = null; + [NotMapped] public Dictionary CourseDiagnoses { get