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; }