예제 #1
0
        public int CreateOrder(Order order)
        {
            decimal orderTotal = 0;
            var cartItems = GetCartItems();

            foreach (var item in cartItems)
            {
                var orderDetail = new OrderDetail
                {
                    GameID = item.GameID,
                    OrderID = order.OrderID,
                    UnitPrice = item.Game.Price,
                    Quantity = item.ItemsCount
                };

                // Set the order total of the shopping cart
                orderTotal += (item.ItemsCount * item.Game.Price);

                storeDB.OrderDetails.Add(orderDetail);

            }

            // Set the order's total to the orderTotal count
            order.Total = orderTotal;

            // Save the order
            storeDB.SaveChanges();

            // Empty the shopping cart
            EmptyCart();

            // Return the OrderId as the confirmation number
            return order.OrderID;
        }
예제 #2
0
        public ActionResult Payment(FormCollection values)
        {
            var order = new Order();
            TryUpdateModel(order);

            try
            {
                    order.UserName = User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    //Save Order
                    storeDB.Orders.Add(order);
                    storeDB.SaveChanges();

                    //Process the order
                    var cart = ShoppingCart.GetCart(this.HttpContext);
                    cart.CreateOrder(order);

                    return RedirectToAction("Complete",
                        new { id = order.OrderID });

            }
            catch
            {
                //Invalid - redisplay with errors
                return View(order);
            }
        }