public List <Product> GetProducts(List <int> IDs)
 {
     using (var context = new GeekHubContext())
     {
         return(context.Products.Where(x => IDs.Contains(x.ID)).ToList());
     }
 }
 public Product GetProduct(int ID)
 {
     using (var context = new GeekHubContext())
     {
         return(context.Products.Find(ID));
     }
 }
 public List <Category> GetFeaturedCategories()
 {
     using (var context = new GeekHubContext())
     {
         return(context.Categories.Where(x => x.IsFeatured && x.ImageURL != null).ToList());
     }
 }
 public List <Product> GetProducts()
 {
     using (var context = new GeekHubContext())
     {
         return(context.Products.Include(x => x.ProductCategory).ToList());
     }
 }
 public Category GetCategory(int ID)
 {
     using (var context = new GeekHubContext())
     {
         return(context.Categories.Find(ID));
     }
 }
 public List <Category> GetCategories()
 {
     using (var context = new GeekHubContext())
     {
         return(context.Categories.ToList());
     }
 }
 public void UpdateProduct(Product Product)
 {
     using (var context = new GeekHubContext())
     {
         context.Entry(Product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void UpdateCategory(Category category)
 {
     using (var context = new GeekHubContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void SaveCategory(Category category)
 {
     using (var context = new GeekHubContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();      //to enter in the database
     }
 }
 public void DeleteProduct(int ID)
 {
     using (var context = new GeekHubContext())
     {
         var Product = GetProduct(ID);
         context.Entry(Product).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
 }
 public void SaveProduct(Product product)
 {
     using (var context = new GeekHubContext())
     {
         context.Entry(product.ProductCategory).State = System.Data.Entity.EntityState.Unchanged;
         context.Products.Add(product);
         context.SaveChanges();      //to enter in the database
     }
 }
 public void DeleteCategory(int ID)
 {
     using (var context = new GeekHubContext())
     {
         var category = GetCategory(ID);
         context.Entry(category).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
 }
 public List <Product> SearchProducts(string search)
 {
     using (var context = new GeekHubContext())
     {
         List <Product> searchResults = new List <Product>();
         var            products      = GetProducts();
         foreach (var p in products)
         {
             if (p.Name != null && p.Name.ToLower().Contains(search.ToLower()))
             {
                 searchResults.Add(p);
             }
         }
         return(searchResults);
     }
 }
        public List <Category> SearchCategories(string search)
        {
            using (var context = new GeekHubContext())
            {
                List <Category> searchResults = new List <Category>();
                var             categories    = GetCategories();
                foreach (var c in categories)
                {
                    if (c.Name != null && c.Name.ToLower().Contains(search.ToLower()))
                    {
                        searchResults.Add(c);
                    }
                }

                return(searchResults);
            }
        }