protected void btnUpdate_Click (object sender, ImageClickEventArgs e) { // Connectiong to BLL MoviesWebSite.BLL.MyShoppingCart userShoppingCart = new BLL.MyShoppingCart(); // Get the session string cartId = userShoppingCart.GetShoppingCartSession(); // Creating an array of data structure MoviesWebSite.BLL.ShoppingCartUpdate[] cartUpdate = new MoviesWebSite.BLL.ShoppingCartUpdate [grvDetails.Rows.Count]; // Use IOrderedDictionary interface that will // enabling us to create an index based on // key/value pair for (int i = 0; i < grvDetails.Rows.Count; i++) { IOrderedDictionary rowValues = new OrderedDictionary(); rowValues = GetValues(grvDetails.Rows[i]); cartUpdate[i].MovieId = Convert.ToInt32(rowValues["MovieID"]); cartUpdate[i].PurchaseQuantity = Convert.ToInt32(rowValues["Quantity"]); CheckBox cbRemove = new CheckBox(); cbRemove = (CheckBox)grvDetails.Rows[i]. FindControl("chkRemove"); cartUpdate[i].RemoveItem = cbRemove.Checked; } // BLL - build the Update for shopping cart // Update shopping Cart userShoppingCart.UpdateShoppingCartDB(cartId, cartUpdate); grvDetails.DataBind(); lblTotal.Text = string.Format("{0:c}", userShoppingCart.GetTotal(cartId)); }
protected void Page_Load(object sender, EventArgs e) { string rowId = Request.QueryString["MovieID"]; int movieId; if (!string.IsNullOrEmpty(rowId) && int.TryParse(rowId, out movieId)) { MoviesWebSite.BLL.MyShoppingCart userShoppingCart = new MoviesWebSite.BLL.MyShoppingCart(); string cartId = userShoppingCart. GetShoppingCartSession(); userShoppingCart.AddItem(cartId, movieId, 1); } else { throw new Exception("Error: Cant load Add To Cart " + "page without movie Id."); } Response.Redirect("MyShoppingCart.aspx"); }