public IEnumerable <VehicleReport> GetByNumberOfSales()
        {
            IEnumerable <Sale> sales = _salesProvider.GetAll();

            var salesPerVehicle = sales.GroupBy(s => s.Vehicle).Select(group => new
            {
                Count   = group.Count(),
                Amount  = group.Sum(s => s.Price),
                Vehicle = group.Key
            })
                                  .OrderByDescending(g => g.Count);

            var result = new List <VehicleReport>();

            foreach (var item in salesPerVehicle)
            {
                result.Add(new VehicleReport()
                {
                    Count       = item.Count,
                    SalesAmount = item.Amount,
                    Vehicle     = item.Vehicle,
                });
            }

            return(result);
        }
예제 #2
0
 public IEnumerable <Sale> Get()
 {
     return(_repository.GetAll());
 }
예제 #3
0
 public IEnumerable <Sale> GetAll()
 {
     return(_provider.GetAll().OrderByDescending(s => s.Date));
 }