// // GET: /PizzaBasket/ public ActionResult Index() { ShoppingBasketHelper helper = new ShoppingBasketHelper(); // Set up our ViewModel var viewModel = new ShoppingBasketViewModel { BasketItems = helper.GetCartItems(), BasketTotal = helper.GetTotal() }; // Return the view return(View(viewModel)); }
public ActionResult Index(FormCollection values) { var order = new Order(); TryUpdateModel(order); try { ShoppingBasketHelper helper = new ShoppingBasketHelper(); decimal priceAfterDiscount = helper.getDiscountedPrice(values["PromoCode"], helper.GetTotal()); order.OrderDate = DateTime.Now; order.OrderStatus = "Undelivered"; order.Total = priceAfterDiscount; db.Orders.Add(order); List <BasketItem> currentItem = helper.GetCartItems(); foreach (BasketItem element in currentItem.ToList()) { var orderDetail = new OrderDetail { ItemId = element.ItemId, OrderId = order.OrderId, UnitPrice = element.Item.ItemPrice, Quantity = element.Count }; db.OrderDetails.Add(orderDetail); } db.SaveChanges(); return(RedirectToAction("Complete", new { orderId = order.OrderId, orderTotal = order.Total })); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } return(View(order)); } }