public Product GetProduct(int id) { using (var _context = new EcartContext()) { return(_context.Products.Where(p => p.Id == id).Include(c => c.Category).FirstOrDefault()); } }
public List <Product> GetProduct(List <int> ids) { using (var _context = new EcartContext()) { return(_context.Products.Where(p => ids.Contains(p.Id)).ToList()); } }
public int GetMaximumPrice() { using (var context = new EcartContext()) { return((int)(context.Products.Max(x => x.UnitPrice))); } }
public List <Product> GetProducts(string search, int pageNo, int pageSize) { using (var context = new EcartContext()) { if (!string.IsNullOrEmpty(search)) { return(context.Products.Where(product => product.Name != null && product.Name.ToLower().Contains(search.ToLower())) .OrderBy(x => x.Id) .Skip((pageNo - 1) * pageSize) .Take(pageSize) .Include(x => x.Category) .ToList()); } else { return(context.Products .OrderBy(x => x.Id) .Skip((pageNo - 1) * pageSize) .Take(pageSize) .Include(x => x.Category) .ToList()); } } }
public List <Product> GetLatestProducts(int numberOfProducts) { using (var context = new EcartContext()) { 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 EcartContext()) { return(context.Products.Where(x => x.Category.Id == categoryID).OrderByDescending(x => x.Id).Take(pageSize).Include(x => x.Category).ToList()); } }
public List <Config> GetConfigurations() { using (var _context = new EcartContext()) { return(_context.Configurations.ToList()); } }
public Config GetConfig(string key) { using (var _context = new EcartContext()) { return(_context.Configurations.Single(x => x.Key == key)); } }
public List <Category> GetFeaturedCategories() { using (var _context = new EcartContext()) { return(_context.Categories.Where(c => c.IsFeatured).Take(4).ToList()); } }
public Category GetCategory(int id) { using (var _context = new EcartContext()) { return(_context.Categories.Single(x => x.Id == id)); } }
public List <Category> GetCategories() { using (var _context = new EcartContext()) { return(_context.Categories.ToList()); } }
public List <Product> GetProducts(int pageNo, int pageSize) { using (var context = new EcartContext()) { return(context.Products.OrderByDescending(x => x.Id).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList()); } }
public List <Product> GetProducts() { using (var _context = new EcartContext()) { return(_context.Products.Include(p => p.Category).ToList()); } }
public void Edit(Config config) { using (var _context = new EcartContext()) { _context.Entry(config).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); } }
public void Create(Config config) { using (var _context = new EcartContext()) { _context.Configurations.Add(config); _context.SaveChanges(); } }
public void Create(Category category) { using (var _context = new EcartContext()) { _context.Categories.Add(category); _context.SaveChanges(); } }
public void Update(Product product) { using (var _context = new EcartContext()) { _context.Entry(product).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); } }
public int ShopPageSize() { using (var context = new EcartContext()) { var pageSizeConfig = context.Configurations.Find("ShopPageSize"); return(pageSizeConfig != null?int.Parse(pageSizeConfig.Value) : 8); } }
public List <Product> GetProducts(int pageNo) { int pageSize = 5;// int.Parse(ConfigurationsService.Instance.GetConfig("ListingPageSize").Value); using (var context = new EcartContext()) { return(context.Products.OrderBy(x => x.Id).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList()); } }
public void Delete(int id) { using (var _context = new EcartContext()) { var product = _context.Products.Find(id); _context.Products.Remove(product); _context.SaveChanges(); } }
public void Create(Product product) { using (var _context = new EcartContext()) { _context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged; _context.Products.Add(product); _context.SaveChanges(); } }
public void Delete(string key) { using (var _context = new EcartContext()) { var config = _context.Configurations.Find(key); _context.Configurations.Remove(config); _context.SaveChanges(); } }
public void Delete(int id) { using (var _context = new EcartContext()) { var category = _context.Categories.Find(id); _context.Categories.Remove(category); _context.SaveChanges(); } }
public int GetProductsCount(string search) { using (var context = new EcartContext()) { if (!string.IsNullOrEmpty(search)) { return(context.Products.Where(product => product.Name != null && product.Name.ToLower().Contains(search.ToLower())) .Count()); } else { return(context.Products.Count()); } } }
public int SearchProductsCount(string searchTerm, int?minPrice, int?maxPrice, int?categoryID, int?sortBy) { using (var context = new EcartContext()) { 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 (minPrice.HasValue) { products = products.Where(x => x.UnitPrice >= minPrice.Value).ToList(); } if (maxPrice.HasValue) { products = products.Where(x => x.UnitPrice <= maxPrice.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.UnitPrice).ToList(); break; default: products = products.OrderByDescending(x => x.UnitPrice).ToList(); break; } } return(products.Count); } }