Merge pull request 'Поправил функции фильтрации процедур' (#9) from change_procedures_storage_logic into stage7_user_web_interface_prototype

Reviewed-on: #9
This commit is contained in:
ekallin 2024-05-01 12:16:13 +04:00
commit 4541576b0c

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,44 @@ 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).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) 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)