예제 #1
0
        private List <ShoppingItem> UpdateCartItems()
        {
            var cart = new ProductCart();

            string cartGuid = cart.GetCartGuid();

            ProductCart.ShoppingCartUpdates[] cartUpdates = new ProductCart.ShoppingCartUpdates[CartList.Rows.Count];
            for (int i = 0; i < CartList.Rows.Count; i++)
            {
                var rowValue = GetValues(CartList.Rows[i]);
                cartUpdates[i].ProductId = int.Parse(rowValue["ProductId"].ToString());

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

                var quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                cartUpdates[i].PurchaseQuantity = int.Parse(quantityTextBox.Text);
            }

            cart.UpdateShoppingCart(cartGuid, cartUpdates);
            CartList.DataBind();
            lblTotal.Text = $"{cart.GetTotal():c}";
            return(cart.GetCartItems());
        }