Exemplo n.º 1
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        //Instantiate the CustomerCart object

        if (Session["CustomerCart"] == null)
        {
            Session["CustomerCart"] = new ShopCart();
        }

        //Access the ProductPK from the DataKeys collection of the DataList

        int intID = Convert.ToInt32(dlGame.DataKeys[0]);

        //Get details about the game from the database
        //Note: These details could have been obtained from the DataList too

        using (GameTableAdapter aAdapter = new GameTableAdapter())
        {
            GameDataTable aTable;

            aTable = aAdapter.GetDataByGameID(intID);

            if (aTable.Rows.Count == 1)
            {
                GameRow aRow = aTable.Rows[0] as GameRow;

                //Add the CartItem

                if (aRow.stock <= 0)
                {
                    Response.Redirect("~/home.aspx");
                }

                ShopCart aCart = Session["CustomerCart"] as ShopCart;

                aCart.AddCartItem(aRow.gameID, aRow.name, aRow.boxImage, 1, aRow.price, aRow.stock);
            }
        }
        Response.Redirect("~/ShoppingCart.aspx");
    }