From 42fcf4bce6863d505990f51e894fcf438273bd5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Tue, 16 May 2023 12:59:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ReportLogic.cs b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ReportLogic.cs index 452594a..369ad61 100644 --- a/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/AutomobilePlant/AbstractAutoBusinessLogic/BusinessLogics/ReportLogic.cs @@ -5,6 +5,8 @@ using AutomobilePlantContracts.BusinessLogicsContracts; using AutomobilePlantContracts.SearchModel; using AutomobilePlantContracts.StoragesContracts; using AutomobilePlantContracts.ViewModel; +using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; namespace AutomobilePlantBusinessLogic.BusinessLogics { @@ -178,27 +180,9 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics public List GetOrdersAll() { var orders = _orderStorage.GetFullList().OrderBy(x => x.DateCreate).ToList(); - Dictionary dictionaryOrders = new Dictionary(); - List< ReportAllOrdersViewModel> list = new List(); - if(orders.Count == 0) return list; - - foreach (var order in orders) - { - if (dictionaryOrders.ContainsKey(order.DateCreate.Date)) - { - dictionaryOrders[order.DateCreate.Date] = (dictionaryOrders[order.DateCreate.Date].Item1 + 1, dictionaryOrders[order.DateCreate.Date].Item2 + order.Sum); - }else - dictionaryOrders.Add(order.DateCreate.Date, (1, order.Sum)); - } - foreach(var order in dictionaryOrders) - { - list.Add(new ReportAllOrdersViewModel - { - DateCreate = order.Key, - Count = order.Value.Item1, - Sum = order.Value.Item2 - }) ; - } + var list = orders.GroupBy(x => x.DateCreate.Date) + .Select(g => new ReportAllOrdersViewModel { DateCreate=g.Key, Count = g.Count(), Sum = g.Sum(g=>g.Sum) }) + .ToList(); return list; }