Example #1
0
        protected void dlBook_ItemCommand(object source, DataListCommandEventArgs e)
        {
            int bookId = Convert.ToInt32(e.CommandArgument.ToString());
            // int bookId = Int32.Parse(e.CommandArgument.ToString());
            BookInfo book = BookManager.GetBookById(bookId);

            if (Session["Cart"] != null)
            {
                CartInfo cart = (CartInfo)Session["Cart"];
                if (CartManager.ExistBook(cart, book))
                {
                    CartManager.IncreaseBook(cart, book, 1);
                }
                else
                {
                    CartManager.AppendBook(cart, book, 1);
                }
            }
            else
            {
                CartInfo cart = CartManager.BuildCart();
                CartManager.AppendBook(cart, book, 1);
                Session["Cart"] = cart;
            }


            Response.Redirect("ShopCart.aspx");
        }