public void Analyze() { var countCustomers = _customerRepository.GetCustomers() .Distinct() .Count(); var countSalesmen = _salesmanRepository.GetSalesmen() .Distinct() .Count(); var orders = _orderRepository .GetOrders() .ToList(); var mostValuableOrder = orders .OrderByDescending(o => o.Total) .FirstOrDefault(); var worstPerformingSalesman = orders .GroupBy(o => o.Salesman) .Select(g => new { salesman = g.Key, yield = g.Sum(o => o.Total) }) .OrderBy(a => a.yield) .FirstOrDefault() ?.salesman; _orderAnalysisRepository.GenerateAnalysis( countCustomers, countSalesmen, mostValuableOrder, worstPerformingSalesman ); }