Пример #1
0
        public IQueryable <Category> GetCategories()
        {
            var _db = new Models.ProductContext();
            IQueryable <Category> query = _db.Categories;

            return(query);
        }
Пример #2
0
 public void UpdateShoppingCartDatabase(String cartId, List <ShoppingCartUpdates> cartUpdates)
 {
     using (var db = new Kidsmeer.Models.ProductContext())
     {
         try
         {
             List <CartItem> myCart = GetCartItems();
             foreach (var cartUpdateItem in cartUpdates)
             {
                 var currentCartItem = myCart.SingleOrDefault(ci => ci.ProductId == cartUpdateItem.ProductId);
                 if (currentCartItem != null)
                 {
                     if (cartUpdateItem.PurchaseQuantity < 1 || cartUpdateItem.RemoveItem)
                     {
                         RemoveItem(currentCartItem.CartId, currentCartItem.ProductId);
                     }
                     else
                     {
                         UpdateItem(cartId, currentCartItem.ProductId, cartUpdateItem.PurchaseQuantity);
                     }
                 }
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
Пример #3
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new Kidsmeer.Models.ProductContext())
     {
         try {
             var myItem = (from c in _db.ShoppingCartItems
                           where c.CartId == removeCartID && c.ProductId == removeProductID
                           select c).FirstOrDefault();
             if (myItem != null)
             {
                 _db.ShoppingCartItems.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
Пример #4
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new Kidsmeer.Models.ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartItems
                           where c.CartId == updateCartID && c.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);
         }
     }
 }