public int CreateOrder(NHOrder 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 NHOrderDetail { AlbumId = item.AlbumId, OrderId = order.Id, UnitPrice = item.Album.Price, Quantity = item.Count }; // Set the order total of the shopping cart orderTotal += (item.Count * item.Album.Price); order.OrderDetails.Add(orderDetail); } // Set the order's total to the orderTotal count order.Total = orderTotal; // Save the order _session.SaveOrUpdate(order); // Empty the shopping cart EmptyCart(); // Return the OrderId as the confirmation number return(order.Id); }
public ActionResult AddressAndPayment(FormCollection values) { var order = new NHOrder(); TryUpdateModel(order); //try //{ if (string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase) == false) { return(View(order as Order)); } else { order.Username = User.Identity.Name; order.OrderDate = DateTime.Now; //Save Order _session.SaveOrUpdate(order); //Process the 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 as Order); //} }