Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string ExportOrdersByEmployee(FastFoodDbContext context, string employeeName, string orderType)
- {
- var type = Enum.Parse<OrderType>(orderType);
- var employee = context.Employees.ToArray()
- .Where(x => x.Name == employeeName)
- .Select(z =>new
- {
- z.Name,
- Orders = z.Orders.Where(o => o.Type == type).Select(o => new
- {
- o.Customer,
- Items = o.OrderItems.Select(oi => new
- {
- oi.Item.Name,
- oi.Item.Price,
- oi.Quantity
- }).ToArray(),
- TotalPrice = o.OrderItems.Sum(oi => oi.Item.Price * oi.Quantity)
- })
- .OrderByDescending(o => o.TotalPrice)
- .ThenByDescending(o => o.Items.Length)
- .ToArray(),
- TotalMade = z.Orders
- .Where(o => o.Type == type)
- .Sum(o => o.OrderItems.Sum(oi => oi.Item.Price * oi.Quantity))
- })
- .SingleOrDefault();
- string result = JsonConvert.SerializeObject(employee,Formatting.Indented);
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment