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

Merged
ekallin merged 2 commits from change_procedures_storage_logic into stage7_user_web_interface_prototype 2024-05-01 12:16:14 +04:00

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using PolyclinicContracts.BindingModels;
using PolyclinicContracts.SearchModels;
using PolyclinicContracts.StoragesContracts;
@ -21,34 +22,44 @@ namespace PolyclinicDatabaseImplement.Implements
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();
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).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;
}
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)