lab-4 change OrderStorage

This commit is contained in:
Zakharov_Rostislav 2024-03-27 12:04:36 +04:00
parent b8c2d2aa96
commit e5df702463
3 changed files with 17 additions and 17 deletions

View File

@ -27,14 +27,15 @@ namespace BlacksmithWorkshopFileImplement.Implements
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
return source.Orders
.Where(x => x.Id == model.Id)
.Select(x => AccessManufactureStorage(x.GetViewModel))
.ToList();
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
(!model.DateTo.HasValue || x.DateCreate <= model.DateTo)
)
)
.Select(x => AccessManufactureStorage(x.GetViewModel))
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{

View File

@ -24,14 +24,15 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
using var context = new BlacksmithWorkshopDataBase();
return context.Orders
.Include(x => x.Manufacture)
.Where(x => x.Id == model.Id)
.Where(x => (
(!model.Id.HasValue || x.Id == model.Id) &&
(!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
(!model.DateTo.HasValue || x.DateCreate <= model.DateTo)
)
)
.Select(x => x.GetViewModel)
.ToList();
}

View File

@ -31,13 +31,11 @@ namespace BlacksmithWorkshopListImplement.Implements
model)
{
var result = new List<OrderViewModel>();
if (!model.Id.HasValue)
{
return result;
}
foreach (var order in _source.Orders)
{
if (order.Id == model.Id)
if ((!model.Id.HasValue || order.Id == model.Id) &&
(!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom)
&& (!model.DateTo.HasValue || order.DateCreate <= model.DateTo))
{
result.Add(AccessManufactureStorage(order.GetViewModel));
}