protected void Page_Load(object sender, EventArgs e)
 {
     string rawId = Request.QueryString["ProductID"];
     int productId;
     if (!String.IsNullOrEmpty(rawId) && Int32.TryParse(rawId, out productId))
     {
         MyShoppingCart usersShoppingCart = new MyShoppingCart();
         String cartId = usersShoppingCart.GetShoppingCartId();
         usersShoppingCart.AddItem(cartId, productId, 1);
     }
     else
     {
         Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ProductId.");
         throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId.");
     }
     Response.Redirect("MyShoppingCart.aspx");
 }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string rawId = Request.QueryString["ProductID"];
            int    productId;

            if (!String.IsNullOrEmpty(rawId) && Int32.TryParse(rawId, out productId))
            {
                MyShoppingCart usersShoppingCart = new MyShoppingCart();
                String         cartId            = usersShoppingCart.GetShoppingCartId();
                usersShoppingCart.AddItem(cartId, productId, 1);
            }
            else
            {
                Debug.Fail("ERROR : We should never get to AddToCart.aspx 
                                                   without a ProductId.");
                throw new Exception("ERROR : It is illegal to load AddToCart.aspx 
                                                   without setting a ProductId.");
            }
            Response.Redirect("MyShoppingCart.aspx");
        }