Esempio n. 1
0
 protected void rptProducts_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "Add")
     {
         HiddenField hdf = (HiddenField)e.Item.FindControl("hdfProductId");
         Product product = new ProductRepo().GetById(ToSQL.SQLToInt(hdf.Value));
         if (product != null)
         {
             List<Cart> carts = (List<Cart>)Session["Carts"];
             Cart cart = new Cart(carts);
             cart = cart.ConverProductToCart(product);
             carts = cart.Add(cart);
             Session["Carts"] = carts;
             Response.Redirect("ViewCart.aspx");
         }
     }
     else if (e.CommandName == "AddCompare")
     {
         CompareAndWish list = (CompareAndWish)Session["Compare"];
         if (list == null)
             list = new CompareAndWish();
         Product p = (new ProductRepo()).GetById(ToSQL.SQLToInt(e.CommandArgument));
         if (p != null && list.Products.Count <= 3)
         {
             if (list.Add(p))
                 Response.Write("<script type='text/javascript'>alert('Added!s');</script>");
             else
                 Response.Write("<script type='text/javascript'>alert('Product is exist in list compare');</script>");
         }
         else
         {
             Response.Write("<script type='text/javascript'>alert('You should select between 1 and 4 item!');</script>");
         }
         UpdateCompareList(list.Products);
         Session["Compare"] = list;
     }
     else if (e.CommandName == "AddWishList")
     {
         CompareAndWish list = (CompareAndWish)Session["WishList"];
         if (list == null)
             list = new CompareAndWish();
         Product p = (new ProductRepo()).GetById(ToSQL.SQLToInt(e.CommandArgument));
         if (p != null)
         {
             if (!list.Add(p))
                 Response.Write("<script type='text/javascript'>alert('Product is exist in list compare');</script>");
         }
         UpdateWishList(list.Products);
         Session["WishList"] = list;
     }
 }
Esempio n. 2
0
        private bool AddCart()
        {
            Product product = new ProductRepo().GetById(ToSQL.SQLToInt(Request.QueryString["ProductId"]));
            if (product != null)
            {
                List<Cart> carts = (List<Cart>)Session["Carts"];
                Cart cart = new Cart(carts);
                cart = cart.ConverProductToCart(product);
                cart.Quantity = ToSQL.SQLToInt(txtQuantity.Text);
                carts = cart.Add(cart);

                //int Quantity = ToSQL.SQLToInt(txtQuantity.Text) - 1;
                //if (Quantity > 0)
                //{
                //    var obj = carts.FirstOrDefault(x => x.ProductID == cart.ProductID);
                //    if (obj != null) obj.Quantity = obj.Quantity + Quantity;
                //}

                Session["Carts"] = carts;
                return true;
            }
            return false;
        }
Esempio n. 3
0
 protected void lbtnAddCart_Click(object sender, EventArgs e)
 {
     LinkButton lbtn = (LinkButton)sender;
     Product product = new ProductRepo().GetById(ToSQL.SQLToInt(lbtn.CommandArgument));
     if (product != null)
     {
         List<Cart> carts = (List<Cart>)Session["Carts"];
         Cart cart = new Cart(carts);
         cart = cart.ConverProductToCart(product);
         carts = cart.Add(cart);
         Session["Carts"] = carts;
         Response.Redirect("ViewCart.aspx");
     }
 }
        protected void lnkRemove_Click(object sender, EventArgs e)
        {
            try
            {
                LinkButton lnk = (LinkButton)sender;
                int Id = ToSQL.SQLToInt(lnk.CommandArgument);
                if (Id > 0)
                {
                    int i = new ProductRepo().DeleteProduct(Id);
                    BindItemsList();
                }
            }
            catch
            {

            }
        }