Merge branch 'lab5_base' into lab5_hard

This commit is contained in:
prodigygirl 2023-04-09 13:52:22 +04:00
commit f7cb58f02b
3 changed files with 41 additions and 6 deletions

View File

@ -31,8 +31,16 @@ namespace FurnitureAssemFileImplement.Implements
{ {
return new(); return new();
} }
if (model.Id.HasValue)
{
return source.Orders
.Where(x => x.Id.Equals(model.Id))
.Select(x => GetOrderViewModel(x))
.ToList();
}
return source.Orders return source.Orders
.Where(x => x.Id.Equals(model.Id) || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || model.ClientId == x.ClientId) .Where(x => !(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) ||
(model.ClientId.HasValue) && !(x.ClientId.Equals(model.ClientId))))
.Select(x => GetOrderViewModel(x)) .Select(x => GetOrderViewModel(x))
.ToList(); .ToList();
} }

View File

@ -29,15 +29,25 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue)
{ {
return new(); return new();
} }
using var context = new FurnitureAssemblyDatabase(); using var context = new FurnitureAssemblyDatabase();
if (model.Id.HasValue)
{
return context.Orders
.Include(x => x.Furniture).Include(x => x.Client)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Orders return context.Orders
.Include(x => x.Furniture) .Include(x => x.Furniture)
.Include(x => x.Client) .Include(x => x.Client)
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || model.ClientId == x.ClientId) .Where(x => !(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) ||
(model.ClientId.HasValue) && !(x.ClientId.Equals(model.ClientId))))
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }

View File

@ -51,14 +51,31 @@ namespace FurnitureAssemblyListImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue && (!model.DateFrom.HasValue || !model.DateTo.HasValue))
{
return new();
}
var result = new List<OrderViewModel>(); var result = new List<OrderViewModel>();
if (model.Id.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.Id.Equals(model.Id))
{
result.Add(GetOrderViewModel(order));
break;
}
}
return result;
}
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
{ {
if (order.Id.Equals(model.Id) || model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo || order.ClientId.Equals(model.ClientId)) if (!(((model.DateFrom.HasValue) && (model.DateTo.HasValue)) && !(model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo) ||
(model.ClientId.HasValue) && !(order.ClientId.Equals(model.ClientId))))
{ {
result.Add(GetOrderViewModel(order)); result.Add(GetOrderViewModel(order));
} }
} }
return result; return result;
} }