public void FillOrder(ref Order newOrder) { ShoppingCart shoppingCartToOrder = GetShoppingCartWithCartItems(newOrder.Username); decimal orderTotal = 0; // Iterate over the items in the cart, adding the order details for each foreach (var item in shoppingCartToOrder.CartItems) { var orderDetail = new OrderDetail { AlbumId = item.AlbumId, OrderId = newOrder.OrderId, UnitPrice = item.Album.Price, Quantity = item.Quantity }; // Set the order total of the shopping cart orderTotal += (item.Quantity * item.Album.Price); newOrder.OrderDetails.Add(orderDetail); } // Set the order's total to the orderTotal count newOrder.Total = orderTotal; // Empty the shopping cart //this.EmptyCart(newOrder.Username); // Return the OrderId as the confirmation number //return newOrder.OrderId; }
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; //Process the order ShoppingCartManager manager = new ShoppingCartManager(); manager.FillOrder(ref order); // Save the order storeDB.Orders.Add(order); storeDB.SaveChanges(); return RedirectToAction("Complete", new { id = order.OrderId }); } } catch { //Invalid - redisplay with errors return View(order); } }