コード例 #1
0
 //
 // GET: /Checkout/AddressAndPayment
 public ActionResult AddressAndPayment()
 {
     ViewBag.firstName = CustomProfile.GetUserProfile(User.Identity.Name).FirstName;
     CustomProfile profile = CustomProfile.GetUserProfile(User.Identity.Name);
     Order model = new Order
     {
         FirstName = CustomProfile.GetUserProfile(User.Identity.Name).FirstName,
         LastName = profile.LastName,
         Address = profile.Address,
         City = profile.City,
         State = profile.State,
         PostalCode = profile.PostalCode,
         Phone = profile.Phone,
     };
     return View(model);
 }
コード例 #2
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();
            var code = RandomCode.Generate();

            order.OrderCode = code;
            order.Active = true;

            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;

                    //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, code = order.OrderCode });
                }

            }
            catch
            {
                //Invalid - redisplay with errors
                return View(order);
            }
        }
コード例 #3
0
        public int 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
                {
                    DrinksId = item.DrinksId,
                    OrderId = order.OrderId,
                    UnitPrice = item.Drinks.price,
                    Quantity = item.Count
                };

                // Set the order total of the shopping cart
                orderTotal += (item.Count * item.Drinks.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;
        }
コード例 #4
0
 public ActionResult Redeem(Order order)
 {
     if (order != null)
     {
         ViewBag.codeAgain = order.OrderCode;
         return View();
     }
     else
     {
         return RedirectToAction("Index", "Home");
     }
     //return View();
 }