Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 19
- public static string GetSalesWithAppliedDiscount(CarDealerContext context)
- {
- var sb = new StringBuilder();
- var sales = context
- .Sales
- .Select(e => new ExportSalesWithAndWithoutDiscounts
- {
- Car = new ExportCarDto
- {
- Make = e.Car.Make,
- Model = e.Car.Model,
- TravelledDistance = e.Car.TravelledDistance
- },
- Discount = Math.Truncate(e.Discount),
- CustomerName = e.Customer.Name,
- Price = e.Car.PartCars.Sum(pc => pc.Part.Price),
- PriceWithDiscount = e.Car.PartCars.Sum(pc => pc.Part.Price) - e.Car.PartCars.Sum(pc => pc.Part.Price) * (e.Discount / 100m)
- })
- .ToArray();
- var xmlSerializer =
- new XmlSerializer(typeof(ExportSalesWithAndWithoutDiscounts[]),
- new XmlRootAttribute("sales"));
- var namespaces = new XmlSerializerNamespaces();
- namespaces.Add("", "");
- using (var writer = new StringWriter(sb))
- {
- xmlSerializer.Serialize(writer, sales, namespaces);
- }
- return sb.ToString().TrimEnd();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement