コード例 #1
0
 public void UpdateShoppingCartDatabase(String cartId, ShoppingCartUpdates[] CartItemUpdates)
 {
     using (var db = new store.Models.ProductContext())
     {
         try
         {
             int CartItemCount         = CartItemUpdates.Count();
             List <CartProduct> myCart = GetCartItems();
             foreach (var cartItem in myCart)
             {
                 for (int i = 0; i < CartItemCount; i++)
                 {
                     if (cartItem.Product.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("Unable to Update Cart Database - " + exp.Message.ToString(), exp);
         }
     }
 }
コード例 #2
0
        public IQueryable <Category> GetCategories()
        {
            var _db = new store.Models.ProductContext();
            IQueryable <Category> query = _db.Categories;

            return(query);
        }
コード例 #3
0
        public IQueryable <Product> FetchCampain([QueryString("category")] string search)
        {
            var _db = new store.Models.ProductContext();
            IQueryable <Product> query = _db.Products;

            if (search != null)
            {
                query = query.Where(p => p.Tag.Contains(search));
            }
            return(query);
        }
コード例 #4
0
        public IQueryable <Product> GetProducts([QueryString("id")] int?categoryId)
        {
            var _db = new store.Models.ProductContext();
            IQueryable <Product> query = _db.Products;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }
            return(query);
        }
コード例 #5
0
        public IQueryable <Product> FetchNewArrivals([QueryString("category")] string newArrivals)
        {
            var _db = new store.Models.ProductContext();
            IQueryable <Product> query = _db.Products;

            if (newArrivals != null)
            {
                query = query.Where(p => p.Tag.Contains(newArrivals));
            }
            return(query);
        }
コード例 #6
0
        public IQueryable <Product> FetchPopular([QueryString("category")] string popular)
        {
            var _db = new store.Models.ProductContext();
            IQueryable <Product> query = _db.Products;

            if (popular != null)
            {
                query = query.Where(p => p.Tag.Contains(popular));
            }
            return(query);
        }
コード例 #7
0
        public IQueryable <Product> SearchResult([QueryString("srch")] string search)
        {
            var _db = new store.Models.ProductContext();
            IQueryable <Product> query = _db.Products;

            if (search != null)
            {
                query = query.Where(p => p.ProductName.Contains(search) || p.Description.Contains(search) || p.Details.Contains(search));
            }
            return(query);
        }
コード例 #8
0
        public IQueryable <Product> GetProduct([QueryString("productID")] int?productId)
        {
            var _db = new store.Models.ProductContext();
            IQueryable <Product> query = _db.Products;

            if (productId.HasValue && productId > 0)
            {
                query = query.Where(p => p.ProductID == productId);
            }
            else
            {
                query = null;
            }
            return(query);
        }
コード例 #9
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var _db = new store.Models.ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartProducts 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("Unable to Update Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }
コード例 #10
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var _db = new store.Models.ProductContext())
     {
         try
         {
             var myItem = (from c in _db.ShoppingCartProducts where c.CartId == removeCartID && c.Product.ProductID == removeProductID select c).FirstOrDefault();
             if (myItem != null)
             {
                 _db.ShoppingCartProducts.Remove(myItem);
                 _db.SaveChanges();
             }
         }
         catch (Exception exp)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + exp.Message.ToString(), exp);
         }
     }
 }