コード例 #1
0
 public void Dispose()
 {
     if (_db != null)
       {
     _db.Dispose();
     _db = null;
       }
 }
コード例 #2
0
ファイル: AddProducts.cs プロジェクト: Azzur/WingTipToys
    public bool AddProduct(string ProductName, string ProductDesc, string ProductPrice, string ProductCategory, string ProductImagePath)
    {
      var myProduct = new Products();
      myProduct.ProductName = ProductName;
      myProduct.Description = ProductDesc;
      myProduct.UnitPrice = Convert.ToDouble(ProductPrice);
      myProduct.ImagePath = ProductImagePath;
      myProduct.CategoryID = Convert.ToInt32(ProductCategory);

      using (wingtiptoysEntities _db = new wingtiptoysEntities())
      {
        // Add product to DB.
        _db.Products.Add(myProduct);
        _db.SaveChanges();
      }
      // Success.
      return true;
    }
コード例 #3
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new wingtiptoysEntities())
       {
     try
     {
       int CartItemCount = CartItemUpdates.Count();
       List<CartItems> myCart = GetCartItems();
       foreach (var cartItem in myCart)
       {
     // Iterate through all rows within shopping cart list
     for (int i = 0; i < CartItemCount; i++)
     {
       if (cartItem.Products.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);
     }
       }
 }
コード例 #4
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new wingtiptoysEntities())
       {
     try
     {
       var myItem = (from c in _db.CartItems where c.CartId == updateCartID && c.Products.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);
     }
       }
 }
コード例 #5
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new wingtiptoysEntities())
       {
     try
     {
       var myItem = (from c in _db.CartItems where c.CartId == removeCartID && c.Products.ProductID == removeProductID select c).FirstOrDefault();
       if (myItem != null)
       {
     // Remove Item.
     _db.CartItems.Remove(myItem);
     _db.SaveChanges();
       }
     }
     catch (Exception exp)
     {
       throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
     }
       }
 }