public List<CartItem> UpdateCartItems() { using (var usersShoppingCart = new ShoppingCartActions()) { var cartId = usersShoppingCart.GetCartId(); var cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[this.CartList.Rows.Count]; for (var i = 0; i < this.CartList.Rows.Count; i++) { var rowValues = GetValues(this.CartList.Rows[i]); cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]); var cbRemove = (CheckBox)this.CartList.Rows[i].FindControl("Remove"); cartUpdates[i].RemoveItem = cbRemove.Checked; var quantityTextBox = (TextBox)this.CartList.Rows[i].FindControl("PurchaseQuantity"); cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text); } usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates); this.CartList.DataBind(); this.lblTotal.Text = $"{usersShoppingCart.GetTotal():c}"; return usersShoppingCart.GetCartItems(); } }
/// <summary> /// The get cart. /// </summary> /// <param name="context"> /// The context. /// </param> /// <returns> /// The <see cref="ShoppingCartActions"/>. /// </returns> public ShoppingCartActions GetCart(HttpContext context) { using (var cart = new ShoppingCartActions()) { cart.ShoppingCartId = cart.GetCartId(); return cart; } }