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()
{
return source.Orders.Select(x => AcessDressesStorage(x.GetViewModel)).ToList();
return source.Orders.Select(x => GetViewModel(x)).ToList();
}
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)
{
if (!model.Id.HasValue)
@ -68,11 +73,20 @@ namespace FishFactoryFileImplement.Implements
source.SaveOrders();
return component.GetViewModel;
}
public OrderViewModel AcessDressesStorage(OrderViewModel model)
{
var component = source.Canneds.FirstOrDefault(x => x.Id == model.CannedId);
model.CannedName = component.CannedName;
return model;
}
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var canned = source.Canneds.FirstOrDefault(x => x.Id == order.CannedId);
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>();
foreach (var order in _source.Orders)
{
result.Add(AccessCannedStorage(order.GetViewModel));
result.Add(GetViewModel(order));
}
return result;
}
@ -31,11 +31,35 @@ namespace FishFactoryListImplement.Implements
model)
{
var result = new List<OrderViewModel>();
if (model.Id.HasValue)
return _source.Orders.Where(x => x.Id == model.Id).Select(x => AccessCannedStorage(x.GetViewModel)).ToList();
else
return _source.Orders.Where(x => x.DateCreate >= model.DateFrom).Where(x => x.DateCreate <= model.DateTo).Select(x => AccessCannedStorage(x.GetViewModel)).ToList();
}
if (!model.Id.HasValue)
{
return result;
}
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)
{
if (!model.Id.HasValue)
@ -94,18 +118,30 @@ namespace FishFactoryListImplement.Implements
}
return null;
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
public OrderViewModel AccessCannedStorage(OrderViewModel model)
{
foreach (var canned in _source.Canneds)
{
if (canned.Id == model.CannedId)
{
model.CannedName = canned.CannedName;
break;
}
}
return model;
}
}
foreach (var canned in _source.Canneds)
{
if (canned.Id == order.CannedId)
{
viewModel.CannedName = canned.CannedName;
break;
}
}
foreach (var client in _source.Clients)
{
if (client.Id == order.ClientId)
{
viewModel.ClientFIO = client.ClientFIO;
break;
}
}
return viewModel;
}
}
}