izmenenia

This commit is contained in:
Дмитрий Блохин 2024-05-15 23:02:20 +04:00
parent 4def3caeeb
commit 599fb9e3fd
2 changed files with 79 additions and 29 deletions

View File

@ -20,12 +20,17 @@ namespace FishFactoryFileImplement.Implements
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
return source.Orders.Select(x => AcessDressesStorage(x.GetViewModel)).ToList(); return source.Orders.Select(x => GetViewModel(x)).ToList();
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
return source.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => AcessDressesStorage(x.GetViewModel)).ToList(); if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue)
} {
return new();
}
return source.Orders.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || x.ClientId == model.ClientId).Select(x => GetViewModel(x)).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue)
@ -68,11 +73,20 @@ namespace FishFactoryFileImplement.Implements
source.SaveOrders(); source.SaveOrders();
return component.GetViewModel; return component.GetViewModel;
} }
public OrderViewModel AcessDressesStorage(OrderViewModel model) private OrderViewModel GetViewModel(Order order)
{ {
var component = source.Canneds.FirstOrDefault(x => x.Id == model.CannedId); var viewModel = order.GetViewModel;
model.CannedName = component.CannedName; var canned = source.Canneds.FirstOrDefault(x => x.Id == order.CannedId);
return model; var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
} if (canned != null)
} {
viewModel.CannedName = canned.CannedName;
}
if (client != null)
{
viewModel.ClientFIO = client.ClientFIO;
}
return viewModel;
}
}
} }

View File

@ -23,7 +23,7 @@ namespace FishFactoryListImplement.Implements
var result = new List<OrderViewModel>(); var result = new List<OrderViewModel>();
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
{ {
result.Add(AccessCannedStorage(order.GetViewModel)); result.Add(GetViewModel(order));
} }
return result; return result;
} }
@ -31,11 +31,35 @@ namespace FishFactoryListImplement.Implements
model) model)
{ {
var result = new List<OrderViewModel>(); var result = new List<OrderViewModel>();
if (model.Id.HasValue) if (!model.Id.HasValue)
return _source.Orders.Where(x => x.Id == model.Id).Select(x => AccessCannedStorage(x.GetViewModel)).ToList(); {
else return result;
return _source.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => AccessCannedStorage(x.GetViewModel)).ToList(); }
}
if (model.ClientId.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.ClientId == model.ClientId)
{
result.Add(GetViewModel(order));
}
}
}
if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.Id == model.Id || model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo)
{
result.Add(GetViewModel(order));
}
}
}
return result;
}
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue)
@ -94,18 +118,30 @@ namespace FishFactoryListImplement.Implements
} }
return null; return null;
} }
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
public OrderViewModel AccessCannedStorage(OrderViewModel model) foreach (var canned in _source.Canneds)
{ {
foreach (var canned in _source.Canneds) if (canned.Id == order.CannedId)
{ {
if (canned.Id == model.CannedId) viewModel.CannedName = canned.CannedName;
{
model.CannedName = canned.CannedName; break;
break; }
} }
}
return model; foreach (var client in _source.Clients)
} {
} if (client.Id == order.ClientId)
{
viewModel.ClientFIO = client.ClientFIO;
break;
}
}
return viewModel;
}
}
} }