public List <Product> GetProducts() { using (var context = new GrovityContext()) { return(context.Products.ToList()); } }
public List <Category> GetFeaturedCategories() { using (var context = new GrovityContext()) { return(context.Categories.Where(x => x.IsFeatured && x.ImageURL != null).ToList()); } }
public List <Product> GetProducts(List <int> IDs) { using (var context = new GrovityContext()) { return(context.Products.Where(product => IDs.Contains(product.ID)).ToList()); } }
public List <Category> GetAllCategories() { using (var context = new GrovityContext()) { return(context.Categories.ToList()); } }
public int GetMaxiumPrice() { using (var context = new GrovityContext()) { return((int)(context.Products.Max(x => x.Price))); } }
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()); } } }
public Category GetCategory(int ID) { using (var context = new GrovityContext()) { return(context.Categories.Find(ID)); } }
public Product GetProduct(int ID) { using (var context = new GrovityContext()) { return(context.Products.Where(x => x.ID == ID).Include(x => x.Category).FirstOrDefault()); } }
public Product GetProduct(int ID) { using (var context = new GrovityContext()) { return(context.Products.Find(ID)); } }
public Config GetConfig(string Key) { using (var context = new GrovityContext()) { return(context.Configurations.Find(Key)); } }
public void UpdateCategory(Category category) { using (var context = new GrovityContext()) { context.Entry(category).State = EntityState.Modified; context.SaveChanges(); } }
public void SaveProduct(Product product) { using (var context = new GrovityContext()) { context.Products.Add(product); context.SaveChanges(); } }
public void UpdateProduct(Product product) { using (var context = new GrovityContext()) { context.Entry(product).State = EntityState.Modified; context.SaveChanges(); } }
public void SaveCategory(Category category) { using (var context = new GrovityContext()) { context.Categories.Add(category); context.SaveChanges(); } }
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()); } }
public void DeleteCategory(int ID) { using (var context = new GrovityContext()) { var category = context.Categories.Find(ID); context.Categories.Remove(category); context.SaveChanges(); } }
public void DeleteProduct(int ID) { using (var context = new GrovityContext()) { var product = context.Products.Find(ID); context.Products.Remove(product); context.SaveChanges(); } }
public void SaveProduct(Product product) { using (var context = new GrovityContext()) { context.Entry(product.Category).State = EntityState.Unchanged; context.Products.Add(product); context.SaveChanges(); } }
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()); } }
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()); } }
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()); } } }
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(); } }
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); } }