From f3d5e963c0e24749df7f076acbc680e7793e868b Mon Sep 17 00:00:00 2001 From: revengel66 Date: Fri, 21 Jun 2024 15:53:01 +0400 Subject: [PATCH] edit orderstorage list 5 lab --- .../Implements/OrderStorage.cs | 49 +++++++++++++++---- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs index 6dd2457..6e106a8 100644 --- a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs @@ -35,7 +35,7 @@ namespace PizzeriaListImplement.Implements } foreach (var order in _source.Orders) { - if ((model.Id.HasValue && order.Id == model.Id)) + if (model.Id.HasValue && order.Id == model.Id) { return AddPizzaName(order.GetViewModel); } @@ -46,31 +46,60 @@ namespace PizzeriaListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (!model.Id.HasValue && !model.DateFrom.HasValue) - { - return result; - } if (model.DateFrom.HasValue) { foreach (var order in _source.Orders) { if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) { - result.Add(AddPizzaName(order.GetViewModel)); + result.Add(GetViewModel(order)); } } - return result; } - foreach (var order in _source.Orders) + else if (model.ClientId.HasValue && !model.Id.HasValue) { - if (order.Id == model.Id) + foreach (var order in _source.Orders) { - result.Add(AddPizzaName(order.GetViewModel)); + if (order.ClientId == model.ClientId) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(GetViewModel(order)); + } } } return result; } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var package in _source.Pizzas) + { + if (package.Id == order.PizzaId) + { + viewModel.PizzaName = package.PizzaName; + break; + } + } + foreach (var client in _source.Clients) + { + if (client.Id == order.ClientId) + { + viewModel.ClientFIO = client.ClientFIO; + break; + } + } + return viewModel; + } public List GetFullList() { var result = new List();