Example #1
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        selectedProduct = new Product();
        this.selectedProduct.Course_id = course_id.ToString();

        if (Page.IsValid)
        {
            CartItemList cart = CartItemList.GetCart();
            int locCount = cart.Count;
            locCount = locCount + 1;
            this.selectedProduct.assignmentNumber = locCount.ToString();
            this.selectedProduct.aGUID = Guid.NewGuid().ToString();
            this.selectedProduct.Num_Assignment = locCount;
            CartItem cartItem = new CartItem();

            int Num_Assignments=0;
            int assignment = 1; //will be produced from loop according to Num_Assignments
            cart = CartItemList.GetCart();
            cartItem = cart[selectedProduct.Course_id];

            if (cartItem == null)
            {
                cart.AddItem(selectedProduct, Num_Assignments,assignment);
            }
            else
            {
                cart.AddItem(selectedProduct, Num_Assignments, assignment);
                cartItem.AddQuantity(1);
            }
            this.DisplayCart();

        }
    }
Example #2
0
    protected void purchaseButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            CartItemList cart     = CartItemList.GetCart();
            CartItem     cartItem = cart[selectedProduct.ProductID];

            if (cartItem == null)
            {
                cart.AddItem(selectedProduct, Convert.ToInt32(quantityTextBox.Text));
            }
            else
            {
                cartItem.AddQuantity(Convert.ToInt32(quantityTextBox.Text));
            }
            Response.Redirect("~/ShoppingPages/Cart.aspx");
        }
    }
 protected void btnAdd_Click1(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         selectedProduct = this.GetSelectedProduct();
         CartItemList cart     = CartItemList.GetCart();
         CartItem     cartItem = cart[selectedProduct.ProductID];
         if (cartItem.Product != selectedProduct)
         {
             cart.AddItem(selectedProduct, 1);
         }
         else
         {
             cartItem.AddQuantity(1);
         }
         Console.WriteLine("PageLoad");
         Response.Redirect("Cart.aspx", false);
     }
 }
Example #4
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //get cart from session state and selected item from cart
            CartItemList cart     = CartItemList.GetCart();
            CartItem     cartItem = cart[selectedProduct.ProductID];

            //if item is nt in cart, add it; else increase its quantity
            if (cartItem == null)
            {
                cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text));
            }
            else
            {
                cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
            }
            Response.Redirect("Cart.aspx");
        }
    }
Example #5
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                Product      selectedProduct = GetSelectedProduct();
                CartItemList cart            = CartItemList.GetCart();
                CartItem     cartItem        = cart[selectedProduct.ProductID];

                if (cartItem == null)
                {
                    cart.AddItem(selectedProduct,
                                 Convert.ToInt32(txtQuantity.Text));
                }
                else
                {
                    cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
                }
                Response.Redirect("Cart");
            }
        }
Example #6
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                CartItemList cart     = CartItemList.GetCart();
                CartItem     cartItem = cart[selectedProduct.ProductID];

                //if item isn't in cart, add it;
                //otherwise, increase its quantity
                if (cartItem == null)
                {
                    cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text));
                }
                else
                {
                    cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
                }
                Response.Redirect("~/Cart.aspx");
            }
        }
Example #7
0
    protected void ButtonCart_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //get cart from session and selected item from cart
            CartItemList cart     = CartItemList.GetCart();
            CartItem     cartItem = cart[selectedProduct.ProductID];

            //if item isn’t in cart, add it; otherwise, increase its quantity
            if (cartItem == null)
            {
                cart.AddItem(selectedProduct,
                             Convert.ToInt32(TextBoxQty.Text));
            }
            else
            {
                cartItem.AddQuantity(Convert.ToInt32(TextBoxQty.Text));
            }
            Response.Redirect("Cart.aspx", false);
        }
    }
Example #8
0
        protected void btnAddToCart_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                //get cart from session state and selected item from cart
                CartItemList cart     = CartItemList.GetCart();
                CartItem     cartItem = cart[displayProduct.Product_id];
                //if item isn't in cart, add it; otherwise, increase its quantity
                if (cartItem == null)
                {
                    cart.AddItem(displayProduct, Convert.ToInt32(txtQuantity.Text));
                    //cart.AddItem(displayProduct);
                }
                else
                {
                    cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
                }

                Response.Redirect("~/MobileCart.aspx");
            }
        }
Example #9
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //get selected product
                var product = GetSelectedProduct(ddlProducts.SelectedValue);

                //get cart from session and selected item from cart
                CartItemList cart     = CartItemList.GetCart();
                CartItem     cartItem = cart[product.ProductID];

                //if item isn’t in cart, add it; otherwise, increase its quantity
                if (cartItem == null)
                {
                    cart.AddItem(product, Convert.ToInt32(txtQuantity.Text));
                }
                else
                {
                    cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
                }
                var url = FriendlyUrl.Href("~/cart", "Cart");
                Response.Redirect(url);
            }
        }
Example #10
0
    protected void btnAddtoCart_Click(object sender, EventArgs e)
    {
        int quantitySelected = 0;

        try{
            quantitySelected = Convert.ToInt16(txtQuantity.Text);

            if (Page.IsValid)
            {
                Cake         selectedProduct = this.GetSelectedProduct();
                CartItemList cart            = CartItemList.GetCart();
                CartItem     cartItem        = cart[selectedProduct.ProductId];


                int index         = 0;
                int alreadyInCart = 0;
                if (cart.Count > 0)
                {
                    while (index != -1)
                    {
                        if (cart.GetProdID(index) == selectedProduct.ProductId)
                        {
                            alreadyInCart = cart.GetQuantity(index);
                        }
                        index = cart.IndexAdvance(index);
                    }
                }
                // checking first to see if we have the amount selected currently on hand
                if (quantitySelected + alreadyInCart <= selectedProduct.OnHand)
                {
                    if (quantitySelected > 0)
                    {
                        // if we do, then we can add to cart and redirect to cart
                        //if item isn't in cart, add it; otherwise, increase its quantity
                        if (cartItem == null)
                        {
                            cart.AddItem(selectedProduct, Convert.ToInt32(txtQuantity.Text));
                        }
                        else
                        {
                            cartItem.AddQuantity(Convert.ToInt32(txtQuantity.Text));
                        }
                        Response.Redirect("~/Cart/Cart.aspx");
                    }
                    else
                    {
                        lblQuan.Text = "Please enter a quantity greater than zero.";
                    }
                }
                else
                {
                    //ask them to order fewer
                    lblQuan.Text = "Sorry, we do not have that many on hand.";
                }
            }
        }
        catch (Exception ex)
        {
            lblQuan.Text = "That's not a valid number.";
        }
    }