Пример #1
0
        //------------------------------------------------------------------------------------------------------------------------------------------+
        protected void UpdateBtn_Click(object sender, ImageClickEventArgs e)
        {
            MyShoppingCart usersShoppingCart = new MyShoppingCart();
            String cartId = usersShoppingCart.GetShoppingCartId();

            ShoppingCartUpdates[] cartUpdates = new ShoppingCartUpdates[MyList.Rows.Count];
            for (int i = 0; i < MyList.Rows.Count; i++)
            {
                IOrderedDictionary rowValues = new OrderedDictionary();
                rowValues = GetValues(MyList.Rows[i]);
                cartUpdates[i].ProductId =  Convert.ToInt32(rowValues["ProductID"]);
                cartUpdates[i].PurchaseQantity = Convert.ToInt32(rowValues["Quantity"]); 

                CheckBox cbRemove = new CheckBox();
                cbRemove = (CheckBox)MyList.Rows[i].FindControl("Remove");
                cartUpdates[i].RemoveItem = cbRemove.Checked;
            }

            usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
            MyList.DataBind();
            lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal(cartId));
        }
Пример #2
0
 //------------------------------------------------------------------------------------------------------------------------------------------+
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (CommerceEntities db = new CommerceEntities())
     {
         try
         {
            int CartItemCOunt = CartItemUpdates.Count();
            var myCart = (from c in db.ViewCarts where c.CartID == cartId select c);
            foreach (var cartItem in myCart)
            {
                // Iterate through all rows within shopping cart list
                for (int i = 0; i < CartItemCOunt; i++)
                {
                    if (cartItem.ProductID == CartItemUpdates[i].ProductId)
                    {
                        if (CartItemUpdates[i].PurchaseQuantity < 1 || CartItemUpdates[i].RemoveItem == true)
                       {
                           RemoveItem(cartId, cartItem.ProductID);
                       }
                    else
                       {
                           UpdateItem(cartId, cartItem.ProductID, CartItemUpdates[i].PurchaseQuantity);
                       }
                    }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }