Exemplo n.º 1
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            var button = (HtmlButton)sender;
            var index  = int.Parse(button.Attributes["index"]);
            var item   = helper.GetAllProducts(basket)[index];

            var repeaterItem = (RepeaterItem)button.NamingContainer;
            var txtQuantity  = (TextBox)repeaterItem.FindControl("txtQuantity" + index);

            if (string.IsNullOrEmpty(txtQuantity.Text))
            {
                helper.RemoveProduct(basket, item);
                var url = WebUtil.GetRawUrl();
                Response.Redirect(url);
            }

            int quantity = int.Parse(txtQuantity.Text);

            if (quantity <= 0)
            {
                helper.RemoveProduct(basket, item);
                var url = WebUtil.GetRawUrl();
                Response.Redirect(url);
            }
            else
            {
                helper.UpdateProduct(item, quantity);
                var url = WebUtil.GetRawUrl();
                Response.Redirect(url);
            }
        }