OrderStorage GetFilteredList fix

This commit is contained in:
ShabOl 2024-04-13 00:46:55 +04:00
parent e61adfda15
commit 74c055bc42
3 changed files with 20 additions and 22 deletions

View File

@ -22,9 +22,6 @@ namespace AutoWorkshopDatabaseImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
{
//if (!Model.Id.HasValue && (!Model.DateFrom.HasValue || !Model.DateTo.HasValue))
// return new();
using var Context = new AutoWorkshopDatabase();
if (Model.DateFrom.HasValue)
@ -32,7 +29,7 @@ namespace AutoWorkshopDatabaseImplement.Implements
return Context.Orders
.Include(x => x.Repair)
.Include(x => x.Client)
.Where(x => x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
.Select(x => x.GetViewModel)
.ToList();
}

View File

@ -3,6 +3,7 @@ using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopFileImplement.Models;
using System;
namespace AutoWorkshopFileImplement.Implements
{
@ -22,13 +23,17 @@ namespace AutoWorkshopFileImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
{
if (!Model.Id.HasValue && (!Model.DateFrom.HasValue || !Model.DateTo.HasValue))
return new();
if (Model.DateFrom.HasValue)
{
return _source.Orders
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
.Select(x => AddClientFIO(AddRepairName(x.GetViewModel)))
.ToList();
}
return _source.Orders
.Where(x => x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo &&
(!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
.Select(x => AddRepairName(x.GetViewModel))
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId))
.Select(x => AddClientFIO(AddRepairName(x.GetViewModel)))
.ToList();
}

View File

@ -29,22 +29,18 @@ namespace AutoWorkshopListImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
{
var Result = new List<OrderViewModel>();
if (!Model.Id.HasValue && (!Model.DateFrom.HasValue || !Model.DateTo.HasValue))
return Result;
foreach (var Order in _source.Orders)
if (Model.DateFrom.HasValue)
{
if ((Order.DateCreate >= Model.DateFrom && Order.DateCreate <= Model.DateTo) &&
(!Model.ClientId.HasValue || Model.ClientId == Model.ClientId))
{
Result.Add(JoinRepairName(Order.GetViewModel));
break;
}
return _source.Orders
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
.Select(x => JoinClientFIO(JoinRepairName(x.GetViewModel)))
.ToList();
}
return Result;
return _source.Orders
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId))
.Select(x => JoinClientFIO(JoinRepairName(x.GetViewModel)))
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel Model)