Exemplo n.º 1
0
        /// <summary>
        /// Updates a single cart item
        /// </summary>
        /// <param name="updateCartID"></param>
        /// <param name="updateProductID"></param>
        /// <param name="quantity"></param>
        public void UpdateItem(string updateCartID, int updateProductID, int quantity)
        {
            using (var _db = new FreddyFruit.Models.ProductContext())
            {
                try
                {
                    var myItem = (from c in _db.ShoppingCartItems
                                  where c.CartId == updateCartID && c.Product.ProductID == updateProductID
                                  select c).FirstOrDefault();

                    if (myItem != null)
                    {
                        myItem.Quantity = quantity;
                        _db.SaveChanges();
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Update Cart Item - " + exp.Message.ToString(), exp);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes an item from the shopping cart
        /// </summary>
        /// <param name="removeCartID"></param>
        /// <param name="removeProductID"></param>
        public void RemoveItem(string removeCartID, int removeProductID)
        {
            using (var _db = new FreddyFruit.Models.ProductContext())
            {
                try
                {
                    var myItem = (from c in _db.ShoppingCartItems
                                  where c.CartId == removeCartID && c.Product.ProductID == removeProductID
                                  select c).FirstOrDefault();

                    if (myItem != null)
                    {
                        // Remove Item.
                        _db.ShoppingCartItems.Remove(myItem);
                        _db.SaveChanges();
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
                }
            }
        }