Поправил функции фильтрации процедур

This commit is contained in:
Никита Потапов 2024-05-01 11:39:01 +04:00
parent 775a442ee8
commit e0ff2d9057

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;
@ -21,34 +22,37 @@ namespace PolyclinicDatabaseImplement.Implements
public List<ProcedureViewModel> GetFilteredList(ProcedureSearchModel model) public List<ProcedureViewModel> 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(); if (!model.Name.IsNullOrEmpty())
return database.Procedures {
.Where(x => x.Id == model.Id || x.Name == model.Name || x.DateStartProcedure <= model.To) elements = elements.Where(x => x.Name == model.Name).ToList();
.Include(p => p.User) }
.Select(x => x.GetViewModel) if (model.From != null)
.ToList(); {
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) public ProcedureViewModel? GetElement(ProcedureSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Name) && return GetFilteredList(model).FirstOrDefault();
!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;
} }
public ProcedureViewModel? Insert(ProcedureBindingModel model) public ProcedureViewModel? Insert(ProcedureBindingModel model)