dimitrix85

GetSalesWithAppliedDiscount

Mar 27th, 2019
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  public static string GetSalesWithAppliedDiscount(CarDealerContext context)
  2.         {
  3.             var sales = context.Sales.Take(10)
  4.                 .Select(x => new
  5.                 {
  6.                     car = new
  7.                     {
  8.                         Make = x.Car.Make,
  9.                         Model = x.Car.Model,
  10.                         TravelledDistance = x.Car.TravelledDistance
  11.                     },
  12.                     customerName = x.Customer.Name,
  13.                     Discount = x.Discount.ToString("F2"),
  14.                     price = x.Car.PartCars.Sum(y => y.Part.Price).ToString("F2"),
  15.                     priceWithDiscount = (x.Car.PartCars.Sum(y => y.Part.Price)-(x.Car.PartCars.Sum(y => y.Part.Price) * x.Discount /100 )).ToString("F2")
  16.                 }).ToArray();
  17.  
  18.             var result = JsonConvert.SerializeObject(sales,Formatting.Indented);
  19.  
  20.             return result;
  21.         }
RAW Paste Data