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; }