Ejemplo n.º 1
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);

                    CheckBox cbRemove = new CheckBox();
                    cbRemove = (CheckBox)CartList.Rows[i].FindControl("Remove");
                    cartUpdates[i].RemoveItem = cbRemove.Checked;

                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
        private List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                ShoppinCartUpdates[] cartUpdates = new ShoppinCartUpdates[CartList.Rows.Count];

                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].produtoId = Convert.ToInt32(rowValues["ProductId"]);

                    CheckBox cbRemove = new CheckBox();
                    cbRemove = (CheckBox)CartList.Rows[i].FindControl("Remove");
                    cartUpdates[i].isRemovedItem = cbRemove.Checked;


                    TextBox TbQuantity = new TextBox();
                    TbQuantity = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].purchaseQuantity = Convert.ToInt32(TbQuantity.Text);
                }

                usersShoppingCart.UpdateShoppingCartDatabase(cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems().ToList());
            }
        }
Ejemplo n.º 3
0
        //UpdatecartItems Method
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    //The amount of products in the cart.
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);


                    //This the checkbox to tick to remove a product.
                    CheckBox cbRemove = new CheckBox();
                    cbRemove = (CheckBox)CartList.Rows[i].FindControl("Remove");
                    cartUpdates[i].RemoveItem = cbRemove.Checked;

                    //This is the textbox to change the quantity.
                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                }

                //This updates the total for all prdoucts in the cart using the GetTotal method.
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
Ejemplo n.º 4
0
        //update cart item with db
        private List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions shopaction = new ShoppingCartActions())
            {
                string cartId = shopaction.GetCartId().ToString();
                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];

                //collect item in cart to update list
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);

                    CheckBox cbRm = CartList.Rows[i].FindControl("Remove") as CheckBox;
                    cartUpdates[i].RemoveItem = cbRm.Checked;

                    TextBox qnt = CartList.Rows[i].FindControl("PurchaseQuantity") as TextBox;
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(qnt.Text);
                }

                shopaction.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = string.Format("{0:c}", shopaction.GetTotal());
                return(shopaction.GetCartItems());
            }
        }
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                List <ShoppingCartActions.ShoppingCartUpdates> cartUpdates = new List <ShoppingCartActions.ShoppingCartUpdates>();
                foreach (GridViewRow row in CartList.Rows)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(row);
                    var ControlCheckbox = (CheckBox)row.FindControl("Remove");
                    var TextBox         = (TextBox)row.FindControl("PurchaseQuantity");
                    ShoppingCartActions.ShoppingCartUpdates cartUpdate = new ShoppingCartActions.ShoppingCartUpdates
                    {
                        ProductId        = Convert.ToInt32(rowValues["ProductID"]),
                        RemoveItem       = ControlCheckbox.Checked,
                        PurchaseQuantity = Convert.ToInt16(TextBox.Text.ToString())
                    };
                    cartUpdates.Add(cartUpdate);
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
Ejemplo n.º 6
0
        public List <CartItem> UpdateRepeats()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new
                                                                        ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);

                    //CheckBox cbRemove = new CheckBox();
                    //cbRemove = (CheckBox)CartList.Rows[i].FindControl("Remove");
                    //cartUpdates[i].RemoveItem = cbRemove.Checked;

                    // DropDownList selectedRepeat = new DropDownList();
                    // selectedRepeat =
                    //(DropDownList)CartList.Rows[i].FindControl("Repeat");
                    // cartUpdates[i].RepeatOrder = selectedRepeat.SelectedValue; /* HERE */

                    //DropDownList selectedRepeat = new DropDownList();
                    DropDownList selectedRepeat = (DropDownList)CartList.Rows[i].FindControl("RepeatOrder");
                    cartUpdates[i].RepeatOrder = selectedRepeat.SelectedValue; /* HERE */
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                //lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
Ejemplo n.º 7
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].LivroId = Convert.ToInt32(rowValues["livro_id"]);

                    CheckBox cbRemove = new CheckBox();
                    cbRemove = (CheckBox)CartList.Rows[i].FindControl("Remover");
                    cartUpdates[i].RemoverItem = cbRemove.Checked;

                    int quantidadeAnterior = GetShoppingCartItems().Cast <CartItem>().ElementAt(i).quantidade;

                    Estoque estoque = commands["CONSULTAR"].execute(new Estoque()
                    {
                        Livro = new Dominio.Livro.Livro()
                        {
                            ID = cartUpdates[i].LivroId
                        }
                    }).Entidades.Cast <Estoque>().ElementAt(0);

                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");

                    if (estoque.Qtde < Convert.ToInt32(quantityTextBox.Text))
                    {
                        cartUpdates[i].PurchaseQuantity = quantidadeAnterior;
                        lblResultadoCarrinho.Text       = "Quantidade em estoque do livro " + estoque.Livro.Titulo + " é de " + estoque.Qtde + " unidade(s)";
                        lblResultadoCarrinho.Visible    = true;
                    }
                    else
                    {
                        cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                        lblResultadoCarrinho.Text       = "";
                        lblResultadoCarrinho.Visible    = false;
                    }
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblSubtotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
Ejemplo n.º 8
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);

                    CheckBox cbRemove = new CheckBox();
                    cbRemove = (CheckBox)CartList.Rows[i].FindControl("Remove");
                    cartUpdates[i].RemoveItem = cbRemove.Checked;

                    TextBox priceTextBox = new TextBox();
                    priceTextBox           = (TextBox)CartList.Rows[i].FindControl("PriceBx");
                    cartUpdates[i].PriceBx = Convert.ToDecimal(priceTextBox.Text.ToString());

                    //cartUpdates[i].ItemPrice = Convert.ToInt32(rowValues["OriginalPrice"]);

                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                //GetTotal() suppose to execute after UpdateShoppingCartDatabase
                string x = String.Format("{0:c}", usersShoppingCart.GetTotal());
                if (x != "$0.00")
                {
                    lblTotal.Text = x;
                }
                else
                {
                    lblTotal.Text = "";
                }
                return(usersShoppingCart.GetCartItems());
            }
        }