Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. //Problem 19
  2. public static string GetSalesWithAppliedDiscount(CarDealerContext context)
  3. {
  4. var sb = new StringBuilder();
  5.  
  6. var sales = context
  7. .Sales
  8. .Select(e => new ExportSalesWithAndWithoutDiscounts
  9. {
  10. Car = new ExportCarDto
  11. {
  12. Make = e.Car.Make,
  13. Model = e.Car.Model,
  14. TravelledDistance = e.Car.TravelledDistance
  15. },
  16. Discount = Math.Truncate(e.Discount),
  17. CustomerName = e.Customer.Name,
  18. Price = e.Car.PartCars.Sum(pc => pc.Part.Price),
  19. PriceWithDiscount = e.Car.PartCars.Sum(pc => pc.Part.Price) - e.Car.PartCars.Sum(pc => pc.Part.Price) * (e.Discount / 100m)
  20. })
  21. .ToArray();
  22.  
  23. var xmlSerializer =
  24. new XmlSerializer(typeof(ExportSalesWithAndWithoutDiscounts[]),
  25. new XmlRootAttribute("sales"));
  26.  
  27. var namespaces = new XmlSerializerNamespaces();
  28. namespaces.Add("", "");
  29.  
  30. using (var writer = new StringWriter(sb))
  31. {
  32. xmlSerializer.Serialize(writer, sales, namespaces);
  33. }
  34.  
  35. return sb.ToString().TrimEnd();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement