public ActionResult DeliveryOrders() { //query the db again and return the list of orders wrapped in the order viewmodel List<Order> orders = db.Orders.Where(x => (int)x.OrderStatus == 2).ToList(); foreach (var order in orders) { var orderDetails = db.OrderDetails.Where(x => x.OrderId == order.OrderId).ToList(); order.OrderDetails = orderDetails; } var orderList = new Orders { Order = orders }; return View(orderList); }
// POST: Orders/Update/2 public async Task<ActionResult> Update(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } try { Order order = await db.Orders.FindAsync(id); if (order == null) { return HttpNotFound(); } bool returnPage = false; //update the order status if (order.OrderStatus == Common.Status.Cooking) { returnPage = true; if (order.DeliveryOption == Common.DeliveryOption.Pickup) { order.OrderStatus = Common.Status.ReadyForPickup; } else { order.OrderStatus = Common.Status.Delivery; } } else if (order.OrderStatus == Common.Status.Delivery) { order.OrderStatus = Common.Status.Complete; } order.CreditCard = "123456789"; //hardcoding this until I fix it later await db.SaveChangesAsync(); //query the db again and return the list of orders wrapped in the order viewmodel List<Order> orders; if (returnPage) { orders = db.Orders.Where(x => x.OrderStatus == 0).ToList(); } else { orders = db.Orders.Where(x => (int)x.OrderStatus == 2).ToList(); } foreach (var ord in orders) { var orderDetails = db.OrderDetails.Where(x => x.OrderId == ord.OrderId).ToList(); ord.OrderDetails = orderDetails; } var orderList = new Orders { Order = orders }; if (returnPage) { return View("CookOrders", orderList); } else { return View("DeliveryOrders", orderList); } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Class: {0}, Property: {1}, Error: {2}", validationErrors.Entry.Entity.GetType().FullName, validationError.PropertyName, validationError.ErrorMessage); } } } return null; }