From 775a442ee8a42b3821fa989c02d82f06c138b40c Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Wed, 1 May 2024 11:20:58 +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=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8E=20=D0=B4=D0=BB=D1=8F=20=D1=81=D1=83=D1=89?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D0=B4=D0=B8=D0=B0=D0=B3=D0=BD?= =?UTF-8?q?=D0=BE=D0=B7,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8E=20=D0=B4=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/DiagnoseViewModel.cs | 4 ++-- .../Implements/DiagnoseStorage.cs | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs b/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs index 7231a42..96093b0 100644 --- a/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs +++ b/Polyclinic/PolyclinicContracts/ViewModels/DiagnoseViewModel.cs @@ -12,10 +12,10 @@ namespace PolyclinicContracts.ViewModels public string Comment { get; set; } = string.Empty; [DisplayName("Дата 'от'")] - public DateTime DateStartDiagnose { get; set; } = DateTime.Now; + public DateTime DateStartDiagnose { get; set; } [DisplayName("Дата 'до'")] - public DateTime? DateStopDiagnose { get; set; } = DateTime.Now; + public DateTime? DateStopDiagnose { get; set; } public int UserId { get; set; } public int Id { get; set; } } diff --git a/Polyclinic/PolyclinicDatabaseImplement/Implements/DiagnoseStorage.cs b/Polyclinic/PolyclinicDatabaseImplement/Implements/DiagnoseStorage.cs index 9baf039..ebb936d 100644 --- a/Polyclinic/PolyclinicDatabaseImplement/Implements/DiagnoseStorage.cs +++ b/Polyclinic/PolyclinicDatabaseImplement/Implements/DiagnoseStorage.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using Microsoft.IdentityModel.Tokens; using PolyclinicContracts.BindingModels; using PolyclinicContracts.SearchModels; using PolyclinicContracts.StoragesContracts; @@ -31,12 +32,25 @@ namespace PolyclinicDatabaseImplement.Implements public List GetFilteredList(DiagnoseSearchModel 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.Value).ToList(); + } + if (!model.Name.IsNullOrEmpty()) + { + elements = elements.Where(x => x.Name == model.Name).ToList(); + } + if (model.UserId != null) + { + elements = elements.Where(x => x.UserId == model.UserId.Value).ToList(); + } + if (model.From != null) + { + elements = elements.Where(x => x.DateStartDiagnose >= model.From.Value).ToList(); + } + if (model.To != null) + { + elements = elements.Where(x => x.DateStopDiagnose <= model.To.Value).ToList(); } return elements; }