Реализовал фильтрацию для сущности диагноз, добавил в фильтрацию даты

This commit is contained in:
Никита Потапов 2024-05-01 11:20:58 +04:00
parent 0e1ca068bd
commit 775a442ee8
2 changed files with 21 additions and 7 deletions

View File

@ -12,10 +12,10 @@ namespace PolyclinicContracts.ViewModels
public string Comment { get; set; } = string.Empty; public string Comment { get; set; } = string.Empty;
[DisplayName("Дата 'от'")] [DisplayName("Дата 'от'")]
public DateTime DateStartDiagnose { get; set; } = DateTime.Now; public DateTime DateStartDiagnose { get; set; }
[DisplayName("Дата 'до'")] [DisplayName("Дата 'до'")]
public DateTime? DateStopDiagnose { get; set; } = DateTime.Now; public DateTime? DateStopDiagnose { get; set; }
public int UserId { get; set; } public int UserId { get; set; }
public int Id { get; set; } public int Id { get; set; }
} }

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using PolyclinicContracts.BindingModels; using PolyclinicContracts.BindingModels;
using PolyclinicContracts.SearchModels; using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts; using PolyclinicContracts.StoragesContracts;
@ -31,12 +32,25 @@ namespace PolyclinicDatabaseImplement.Implements
public List<DiagnoseViewModel> GetFilteredList(DiagnoseSearchModel model) public List<DiagnoseViewModel> GetFilteredList(DiagnoseSearchModel model)
{ {
var elements = GetFullList(); 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.Id == model.Id.Value).ToList();
{
elements = elements.Where(x => x.GetType().GetProperty(prop.Name)?.GetValue(x, null) == model.GetType().GetProperty(prop.Name)?.GetValue(model, null)).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; return elements;
} }