Пример #1
0
 public List <Product> GetProducts()
 {
     using (var context = new GrovityContext())
     {
         return(context.Products.ToList());
     }
 }
Пример #2
0
 public List <Category> GetFeaturedCategories()
 {
     using (var context = new GrovityContext())
     {
         return(context.Categories.Where(x => x.IsFeatured && x.ImageURL != null).ToList());
     }
 }
Пример #3
0
 public List <Product> GetProducts(List <int> IDs)
 {
     using (var context = new GrovityContext())
     {
         return(context.Products.Where(product => IDs.Contains(product.ID)).ToList());
     }
 }
Пример #4
0
 public List <Category> GetAllCategories()
 {
     using (var context = new GrovityContext())
     {
         return(context.Categories.ToList());
     }
 }
Пример #5
0
 public int GetMaxiumPrice()
 {
     using (var context = new GrovityContext())
     {
         return((int)(context.Products.Max(x => x.Price)));
     }
 }
Пример #6
0
        public List <Category> GetCategories(string search, int pageNo)
        {
            int pageSize = 2;

            using (var context = new GrovityContext())
            {
                if (!string.IsNullOrEmpty(search))
                {
                    return(context.Categories.Where(category => category.Name != null &&
                                                    category.Name.ToLower().Contains(search.ToLower()))
                           .OrderBy(x => x.ID)
                           .Skip((pageNo - 1) * pageSize)
                           .Take(pageSize)
                           .Include(x => x.Products)
                           .ToList());
                }
                else
                {
                    return(context.Categories
                           .OrderBy(x => x.ID)
                           .Skip((pageNo - 1) * pageSize)
                           .Take(pageSize).Include(x => x.Products)
                           .ToList());
                }
            }
        }
Пример #7
0
 public Category GetCategory(int ID)
 {
     using (var context = new GrovityContext())
     {
         return(context.Categories.Find(ID));
     }
 }
Пример #8
0
 public Product GetProduct(int ID)
 {
     using (var context = new GrovityContext())
     {
         return(context.Products.Where(x => x.ID == ID).Include(x => x.Category).FirstOrDefault());
     }
 }
Пример #9
0
 public Product GetProduct(int ID)
 {
     using (var context = new GrovityContext())
     {
         return(context.Products.Find(ID));
     }
 }
Пример #10
0
 public Config GetConfig(string Key)
 {
     using (var context = new GrovityContext())
     {
         return(context.Configurations.Find(Key));
     }
 }
Пример #11
0
        public void UpdateCategory(Category category)
        {
            using (var context = new GrovityContext())
            {
                context.Entry(category).State = EntityState.Modified;

                context.SaveChanges();
            }
        }
Пример #12
0
        public void SaveProduct(Product product)
        {
            using (var context = new GrovityContext())
            {
                context.Products.Add(product);

                context.SaveChanges();
            }
        }
Пример #13
0
        public void UpdateProduct(Product product)
        {
            using (var context = new GrovityContext())
            {
                context.Entry(product).State = EntityState.Modified;

                context.SaveChanges();
            }
        }
Пример #14
0
        public void SaveCategory(Category category)
        {
            using (var context = new GrovityContext())
            {
                context.Categories.Add(category);

                context.SaveChanges();
            }
        }
Пример #15
0
 public List <Product> GetProducts(int pageNo, int pageSize)
 {
     using (var context = new GrovityContext())
     {
         return(context.Products
                .OrderByDescending(x => x.ID)
                .Skip((pageNo - 1) * pageSize)
                .Take(pageSize)
                .Include(x => x.Category).ToList());
     }
 }
Пример #16
0
        public void DeleteCategory(int ID)
        {
            using (var context = new GrovityContext())
            {
                var category = context.Categories.Find(ID);

                context.Categories.Remove(category);

                context.SaveChanges();
            }
        }
Пример #17
0
        public void DeleteProduct(int ID)
        {
            using (var context = new GrovityContext())
            {
                var product = context.Products.Find(ID);

                context.Products.Remove(product);

                context.SaveChanges();
            }
        }
Пример #18
0
        public void SaveProduct(Product product)
        {
            using (var context = new GrovityContext())
            {
                context.Entry(product.Category).State = EntityState.Unchanged;

                context.Products.Add(product);

                context.SaveChanges();
            }
        }
Пример #19
0
 public List <Product> GetLatestProducts(int numberOfProducts)
 {
     using (var context = new GrovityContext())
     {
         return(context.Products
                .OrderByDescending(x => x.ID)
                .Take(numberOfProducts)
                .Include(x => x.Category)
                .ToList());
     }
 }
Пример #20
0
 public List <Product> GetProductsByCategory(int categoryID, int pageSize)
 {
     using (var context = new GrovityContext())
     {
         return(context.Products
                .Where(x => x.Category.ID == categoryID)
                .OrderByDescending(x => x.ID)
                .Take(pageSize)
                .Include(x => x.Category).ToList());
     }
 }
Пример #21
0
 public int GetCategoriesCount(string search)
 {
     using (var context = new GrovityContext())
     {
         if (!string.IsNullOrEmpty(search))
         {
             return(context.Categories.Where(category => category.Name != null &&
                                             category.Name.ToLower().Contains(search.ToLower())).Count());
         }
         else
         {
             return(context.Categories.Count());
         }
     }
 }
Пример #22
0
        public List <Product> GetProducts(int pageNo)
        {
            int pageSize = 5;// int pageSize = int.Parse(ConfigurationService.Instance.GetConfig("ListingPageSize").Value);

            using (var context = new GrovityContext())
            {
                return(context.Products
                       .OrderBy(x => x.ID)
                       .Skip((pageNo - 1) * pageSize)
                       .Take(pageSize)
                       .Include(x => x.Category).ToList());

                // return context.Products.Include(x => x.Category).ToList();
            }
        }
Пример #23
0
        public List <Product> SearchProducts(string searchTerm, int?minimumPrice, int?maximumPrice, int?categoryID, int?sortBy)
        {
            using (var context = new GrovityContext())
            {
                var products = context.Products.ToList();

                if (categoryID.HasValue)
                {
                    products = products.Where(x => x.Category.ID == categoryID.Value).ToList();
                }
                if (!string.IsNullOrEmpty(searchTerm))
                {
                    products = products.Where(x => x.Name.ToLower().Contains(searchTerm.ToLower())).ToList();
                }
                if (minimumPrice.HasValue)
                {
                    products = products.Where(x => x.Price >= minimumPrice.Value).ToList();
                }
                if (maximumPrice.HasValue)
                {
                    products = products.Where(x => x.Price >= maximumPrice.Value).ToList();
                }
                if (sortBy.HasValue)
                {
                    switch (sortBy.Value)
                    {
                    case 2:
                        products = products.OrderByDescending(x => x.ID).ToList();
                        break;

                    case 3:
                        products = products.OrderBy(x => x.Price).ToList();
                        break;

                    default:
                        products = products.OrderByDescending(x => x.Price).ToList();
                        break;
                    }
                }
                return(products);
            }
        }