From e0ff2d9057aa221dc476cefb6200b38fc4fa57f5 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Wed, 1 May 2024 11:39:01 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=86=D0=B5=D0=B4=D1=83=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ProcedureStorage.cs | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs index c596909..0194d9d 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; using PolyclinicContracts.BindingModels; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; @@ -21,34 +22,37 @@ namespace PolyclinicDatabaseImplement.Implements public List GetFilteredList(ProcedureSearchModel model) { - if (!model.Id.HasValue && !model.From.HasValue && !model.To.HasValue && !model.UserId.HasValue) + var elements = GetFullList(); + if (model.Id != null) { - return new(); + elements = elements.Where(x => x.Id == model.Id.Value).ToList(); } - if (string.IsNullOrEmpty(model.Name)) + if (model.UserId != null) { - return new(); + elements = elements.Where(x => x.UserId == model.UserId.Value).ToList(); } - using var database = new PolyclinicDatabase(); - return database.Procedures - .Where(x => x.Id == model.Id || x.Name == model.Name || x.DateStartProcedure <= model.To) - .Include(p => p.User) - .Select(x => x.GetViewModel) - .ToList(); + if (!model.Name.IsNullOrEmpty()) + { + elements = elements.Where(x => x.Name == model.Name).ToList(); + } + if (model.From != null) + { + elements = elements.Where(x => x.DateStartProcedure >= model.From.Value).ToList(); + } + if (model.To != null) + { + elements = elements + .Where(x => x.DateStartProcedure <= model.To.Value) + .Where(x => x.DateStopProcedure != null) + .Where(x => x.DateStopProcedure <= model.To.Value) + .ToList(); + } + return elements; } public ProcedureViewModel? GetElement(ProcedureSearchModel model) { - if (string.IsNullOrEmpty(model.Name) && - !model.Id.HasValue) - { - return null; - } - using var database = new PolyclinicDatabase(); - return database.Procedures - .Include(p => p.User) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || - (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return GetFilteredList(model).FirstOrDefault(); } public ProcedureViewModel? Insert(ProcedureBindingModel model) From 4377f8e5ae7081f7f67b6f4a42a64138dd8af735 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Wed, 1 May 2024 11:53:43 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=84=D0=B8?= =?UTF-8?q?=D0=BB=D1=8C=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=86=D0=B5=D0=B4=D1=83=D1=80=20=D0=BF=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=B0=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ProcedureStorage.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs index 0194d9d..e172d21 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/ProcedureStorage.cs @@ -41,11 +41,18 @@ namespace PolyclinicDatabaseImplement.Implements } if (model.To != null) { - elements = elements - .Where(x => x.DateStartProcedure <= model.To.Value) + elements = elements.Where(x => x.DateStartProcedure <= model.To.Value).ToList(); + + var elemWithDateStop = elements .Where(x => x.DateStopProcedure != null) .Where(x => x.DateStopProcedure <= model.To.Value) .ToList(); + + var elemWithoutDateStop = elements.Where(x => x.DateStopProcedure == null).ToList(); + + elemWithDateStop.AddRange(elemWithoutDateStop); + + elements = elemWithDateStop; } return elements; }