Advertisement
Guest User

problem 17

a guest
Aug 1st, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. public static string GetSalesWithAppliedDiscount(CarDealerContext context)
  2. {
  3. var sales = context.Sales
  4. .Take(10)
  5. .Select(x => new
  6. {
  7. car = new
  8. {
  9. Make = x.Car.Make,
  10. Model = x.Car.Model,
  11. TravelledDistance = x.Car.TravelledDistance
  12. },
  13.  
  14. customerName = x.Customer.Name,
  15. Discount = $"{x.Discount:F2}",
  16. price = $"{x.Car.PartCars.Sum(y => y.Part.Price):F2}",
  17. priceWithDiscount = $"{x.Car.PartCars.Sum(y => y.Part.Price) - (x.Car.PartCars.Sum(y => y.Part.Price) * (x.Discount / 100)):F2}",
  18. })
  19. .ToList();
  20.  
  21. string json = JsonConvert.SerializeObject(sales,Formatting.Indented);
  22.  
  23. return json;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement