/* Update the shopping cart total when the delete item button is press or the quantity of the item changes */ public List<CartItem> UpdateCartItems() { using (ShoppingCartFunctions usersShoppingCart = new ShoppingCartFunctions()) { String cartId = usersShoppingCart.GetCartId(); ShoppingCartFunctions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartFunctions.ShoppingCartUpdates[CartList.Rows.Count]; for (int i = 0; i < CartList.Rows.Count; i++) { IOrderedDictionary rowValues = new OrderedDictionary(); rowValues = GetValues(CartList.Rows[i]); cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]); CheckBox cbRemove = new CheckBox(); cbRemove = (CheckBox)CartList.Rows[i].FindControl("Delete"); cartUpdates[i].RemoveItem = cbRemove.Checked; TextBox quantityTextBox = new TextBox(); quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity"); cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString()); } usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates); CartList.DataBind(); var cartTotal = usersShoppingCart.GetTotal(); var tax = (decimal)0.07 * (cartTotal + (decimal)5.00); var total = cartTotal + tax; lbltaxTotal.Text = String.Format("{0:c}", tax); lblTotal.Text = String.Format("{0:c}", total); return usersShoppingCart.GetCartItems(); } }
/* Obtain all cart items */ public List<CartItem> GetShoppingCartItems() { ShoppingCartFunctions actions = new ShoppingCartFunctions(); return actions.GetCartItems(); }