public ActionResult AddressAndPayment(FormCollection values) { var order = new Order(); TryUpdateModel(order); try { if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false) { return(View(order)); } else { order.Username = User.Identity.Name; order.OrderDate = DateTime.Now; _orderPersister.Store(order); var cart = ShoppingCart.GetCart(this.HttpContext); cart.CreateOrder(order); return(RedirectToAction("Complete", new { id = order.Id })); } } catch { //Invalid - redisplay with errors return(View(order)); } }
public string CreateOrder(Order order) { decimal orderTotal = 0; var cartItems = GetCartItems(); foreach (var item in cartItems) { var orderDetail = new OrderDetail { Album = item.Album, Order = order, UnitPrice = item.Album.Price, Quantity = item.Count }; orderTotal += (item.Count * item.Album.Price); order.OrderDetails.Add(orderDetail); } order.Total = orderTotal; _orderPersister.Store(order); EmptyCart(); return(order.Id); }
public string CreateOrder(Order order) { decimal orderTotal = 0; var cartItems = GetCartItems(); // Iterate over the items in the cart, adding the order details for each foreach (var item in cartItems) { var orderDetail = new OrderDetail { Album = item.Album, Order = order, UnitPrice = item.Album.Price, Quantity = item.Count }; // Set the order total of the shopping cart orderTotal += (item.Count * item.Album.Price); // storeDB.OrderDetails.Add(orderDetail); order.OrderDetails.Add(orderDetail); } // Set the order's total to the orderTotal count order.Total = orderTotal; // Save the order // storeDB.SaveChanges(); _orderPersister.Store(order); // Empty the shopping cart EmptyCart(); // Return the Id as the confirmation number return(order.Id); }