コード例 #1
0
ファイル: CheckoutController.cs プロジェクト: argetima/Golex
        //
        // GET: /Checkout/AddressAndPayment
        public ActionResult AddressAndPayment()
        {
            string userId = User.Identity.GetUserId();
            ApplicationUser user = storeDB.Users.Where(u => u.Id == userId).FirstOrDefault();
            Order o = new Order();
            o.Address = user.address;
            o.Phone = user.PhoneNumber;
            o.Email = user.Email;

            return View(o);
        }
コード例 #2
0
ファイル: CheckoutController.cs プロジェクト: argetima/Golex
        public ActionResult AddressAndPayment(Pizza.Models.Order model)
        {
            var order = new Order();

            TryUpdateModel(order);

            try
            {
                //if (string.Equals(values["PromoCode"], PromoCode,
                //    StringComparison.OrdinalIgnoreCase) == false)
                //{
                //    return View(order);
                //}
                //else
                {
                    string username = User.Identity.Name;
                    var    user     = storeDB.Users.Where(u => u.UserName == username).FirstOrDefault();
                    //ShoppingCart ShoppingCart = new ShoppingCart();

                    order.username = user.UserName;
                    order.datetime = DateTime.Now;
                    order.Address  = model.Address;
                    order.Phone    = user.PhoneNumber;
                    order.Email    = user.Email;

                    //order.Total = ShoppingCart.GetTotal();
                    //Save Order
                    storeDB.orders.Add(order);
                    storeDB.SaveChanges();

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

                    return(RedirectToAction("Complete", new { id = order.id }));
                }
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
コード例 #3
0
ファイル: CheckoutController.cs プロジェクト: argetima/Golex
        public ActionResult AddressAndPayment(Pizza.Models.Order model)
        {
            var order = new Order();
            TryUpdateModel(order);

            try
            {
                //if (string.Equals(values["PromoCode"], PromoCode,
                //    StringComparison.OrdinalIgnoreCase) == false)
                //{
                //    return View(order);
                //}
                //else
                {
                    string username = User.Identity.Name;
                    var user = storeDB.Users.Where(u => u.UserName == username).FirstOrDefault();
                    //ShoppingCart ShoppingCart = new ShoppingCart();

                    order.username = user.UserName;
                    order.datetime = DateTime.Now;
                    order.Address = model.Address;
                    order.Phone = user.PhoneNumber;
                    order.Email = user.Email;

                    //order.Total = ShoppingCart.GetTotal();
                    //Save Order
                    storeDB.orders.Add(order);
                    storeDB.SaveChanges();

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

                    return RedirectToAction("Complete", new { id = order.id });
                }
            }
            catch
            {
                //Invalid - redisplay with errors
                return View(order);
            }
        }
コード例 #4
0
ファイル: ShoppingCart.cs プロジェクト: argetima/Golex
        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 OrderDetails
                {
                    id = item.ItemId,
                    ItemId = order.id,
                    price = item.Item.price,
                    quantity = item.Count,
                    item = getItemFromModel(item.ItemId),
                    order = order

                };
                // Set the order total of the shopping cart
                orderTotal += (item.Count * item.Item.price);

                storeDB.orderDetails.Add(orderDetail);
            }
            // Set the order's total to the orderTotal count
            //var orderInserted = storeDB.orders.Where(o => o.id == order.id).FirstOrDefault();
            PaymentMethod pm = storeDB.paymentMethod.Where(p => p.active == true).FirstOrDefault();
            order.PaymentMethod = pm;
            order.Total = orderTotal;
            storeDB.Entry(order).State = System.Data.Entity.EntityState.Modified;
            // Save the order
            storeDB.SaveChanges();
            // Empty the shopping cart
            EmptyCart();
            // Return the OrderId as the confirmation number
            return order.id;
        }