private List <GetFoodOrderVm> GetFoodReceipts(List <UserOrder> userOrders) { var foodReceipts = new List <GetFoodOrderVm>(); foreach (var userOrder in userOrders) { foreach (var foodOrder in userOrder.FoodOrders) { var newFoodRecept = new GetFoodOrderVm { FoodOrderId = foodOrder.Id, FoodId = foodOrder.Food.Id, Title = foodOrder.Food.Title, Cost = foodOrder.Food.Cost, Comment = foodOrder.Comment, Count = foodOrder.Count, UserId = userOrder.User.Id, UserName = userOrder.User.Name }; foodReceipts.Add(newFoodRecept); } } return(foodReceipts); }
private List <UserGroupedReceiptVm> GetUserGroupedReceipts(List <UserOrder> userOrders, float deliveryCostPerUser) { var userGroupedReceipts = new List <UserGroupedReceiptVm>(); foreach (var userOrder in userOrders) { var foodCost = userOrder.FoodOrders.Select(fo => fo.Count * fo.Food.Cost).Sum(); var userReceipt = new UserGroupedReceiptVm() { FoodCost = foodCost, DeliveryCost = deliveryCostPerUser, Total = foodCost + deliveryCostPerUser, Name = userOrder.User.Name, IsOrderPaid = userOrder.IsOrderPaid, UserId = userOrder.User.Id }; userReceipt.FoodOrders = new List <GetFoodOrderVm>(); foreach (var foodOrder in userOrder.FoodOrders) { var newFoodRecept = new GetFoodOrderVm { FoodOrderId = foodOrder.Id, FoodId = foodOrder.Food.Id, Title = foodOrder.Food.Title, Cost = foodOrder.Food.Cost, Comment = foodOrder.Comment, Count = foodOrder.Count, UserId = userOrder.User.Id, UserName = userOrder.User.Name }; userReceipt.FoodOrders.Add(newFoodRecept); } userGroupedReceipts.Add(userReceipt); } return(userGroupedReceipts); }