Exemple #1
0
        public Order(string username, String accountType, ShoppingCart cart)
        {
            this.cart = (ShoppingCart) cart;

            if (accountType.Equals("Personal"))
            {
                customerDetails = new Customer(username);
                country = customerDetails.country;
            }
            else
            {
                retailerDetails = new Retailer();
                retailerDetails.getRetailer(username);
                country = retailerDetails.country;
            }

            paymentDetails = new Payment(username, accountType);
            getShippersDetails();

            getTotals();
        }
        // Post: /Checkout/CompleteOrderProcess
        public ActionResult CompleteOrderProcess(Order order, int shippersID)
        {
            if (ModelState.IsValid)
            {
                ShoppingCart cart = (ShoppingCart)Session["cart"];
                String accountType = Session["account"].ToString();
                Order newOrder = new Order(Session["loginName"].ToString(), accountType, cart);
                newOrder.shippersId = Convert.ToInt32(shippersID);
                newOrder.getSingleShippersDetails();
                newOrder.getTotals();
                newOrder.completeOrderInfo(Session["loginName"].ToString(), Session["account"].ToString());

                ShoppingCart newCart = new ShoppingCart(Session["loginName"].ToString());
                newCart.setTotals();
                Session["itemCount"] = newCart.totalItemCount;
                Session["cart"] = newCart;

                return RedirectToAction("CompleteOrder");
            }
            else
            {
                return View(order);
            }
        }
        // GET: /Checkout/
        public ActionResult Index()
        {
            if (Session["CartSessionKey"] == null)
            {
                if (Session["loggedIn"] != null)
                {
                    Session["CartSessionKey"] = Session["loginName"].ToString();
                    ShoppingCart cart = new ShoppingCart(Session["loginName"].ToString());
                    String accountType = Session["account"].ToString();
                    Session["cart"] = cart;
                    Order order = new Order(Session["loginName"].ToString(), accountType, cart);
                    View(order);
                }
                else
                {
                    // Generate a new random GUID using System.Guid class
                    Guid tempCartId = Guid.NewGuid();
                    // Send tempCartId back to client as a cookie
                    Session["CartSessionKey"] = tempCartId.ToString();
                    ShoppingCart cart = new ShoppingCart(tempCartId.ToString());
                    String accountType = "Personal";
                    Session["cart"] = cart;
                    Order order = new Order(null, accountType, cart);
                    View(order);
                }
            }
            else
            {
                if (Session["loggedIn"] != null)
                {
                    ShoppingCart cart = (ShoppingCart)Session["cart"];
                    String accountType = Session["account"].ToString();
                    Order order = new Order(Session["loginName"].ToString(), accountType, cart);
                    return View(order);
                }
                else
                {
                    ShoppingCart cart = (ShoppingCart)Session["cart"];
                    String accountType = "Personal";
                    Order order = new Order(null, accountType, cart);
                    return View(order);
                }
            }

            return View();
        }