Пример #1
0
        public bool AddProduct(string ProductName, string ProductDesc, string ProductPrice, string ProductCategory, string ProductImagePath)
        {
            var myProduct = new Product();
            myProduct.ProductName = ProductName;
            myProduct.Description = ProductDesc;
            myProduct.UnitPrice = Convert.ToDouble(ProductPrice);
            myProduct.ImagePath = ProductImagePath;
            myProduct.CategoryID = Convert.ToInt32(ProductCategory);

            using (ProductContext _db = new ProductContext())
            {
                // Add product to DB.
                _db.Products.Add(myProduct);
                _db.SaveChanges();
            }
            // Success.
            return true;
        }
Пример #2
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new ClusterCart.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);
         }
     }
 }
Пример #3
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new ClusterCart.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);
         }
     }
 }