dimitrix85

GetTotalSalesByCustomer

Mar 27th, 2019
55
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  public static string GetTotalSalesByCustomer(CarDealerContext context)
  2.         {
  3.             var custemers = context.Customers.Where(x => x.Sales.Any(y => y.Car != null))
  4.                 .OrderByDescending(x => x.Sales.Sum(y => y.Car.PartCars.Sum(s => s.Part.Price)))
  5.                 .ThenByDescending(x => x.Sales.Count())
  6.                 .Select(x => new
  7.                 {
  8.                     fullName = x.Name,
  9.                     boughtCars = x.Sales.Count(),
  10.                     spentMoney = x.Sales.Sum(y=>y.Car.PartCars.Sum(s=>s.Part.Price))
  11.                 })
  12.                
  13.                 .ToArray();
  14.  
  15.             var result = JsonConvert.SerializeObject(custemers, Formatting.Indented);
  16.  
  17.             return result;
  18.         }
RAW Paste Data