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); UpdateLabelShipping(carts); 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('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; } }
protected void rptProducts_ItemCommand(object source, RepeaterCommandEventArgs e) { if (Session["WishList"] != null && e.CommandName == "Remove") { CompareAndWish list = (CompareAndWish)Session["WishList"]; HiddenField hdf = (HiddenField)e.Item.FindControl("hdfProductId"); if (list != null) { list.Remove(ToSQL.SQLToInt(hdf.Value)); LoadWishList(); } } }
private void LoadWishList() { if (Session["WishList"] != null) { CompareAndWish list = (CompareAndWish)Session["WishList"]; if (list == null || list.Products.Count <= 0) { Response.Redirect("~/Index.aspx"); } rptProducts.DataSource = list.Products; rptProducts.DataBind(); } }
protected void rptComapre_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "Remove" && Session["Compare"] != null) { CompareAndWish list = (CompareAndWish)Session["Compare"]; if (list != null) { list.Remove(ToSQL.SQLToInt(e.CommandArgument)); Session["Compare"] = list; LoadCompareList(); } } }
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; } }
private void LoadCompareList() { if (Session["Compare"] != null) { CompareAndWish list = (CompareAndWish)Session["Compare"]; if (list == null || list.Products.Count == 0) { Response.Redirect("~/Index.aspx"); } dtlCompare.DataSource = list.Products; dtlCompare.DataBind(); rptComapre.DataSource = list.Products; rptComapre.DataBind(); } else { Response.Redirect("~/Index.aspx"); } }
public void LoadWishList() { if (Session["WishList"] != null) { CompareAndWish list = (CompareAndWish)Session["WishList"]; if (list != null) { if (list.Products.Count > 0) { rptWishList.DataSource = list.Products; rptWishList.Visible = true; } else { rptWishList.DataSource = null; rptWishList.Visible = false; } rptWishList.DataBind(); } } }