public List <Product> GetWidgetProducts(int pageNo, int pageSize) { using (var context = new CbContext()) { return(context.Products.OrderByDescending(x => x.Id).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList()); } }
public tbl_Location GetLocations() { using (var context = new CbContext()) { return(context.tbl_Locations.FirstOrDefault()); } }
public List <tbl_State> GetStates() { using (var context = new CbContext()) { return(context.tbl_States.ToList()); } }
public Category GetCategoryById(int id) { using (var context = new CbContext()) { return(context.Categories.Find(id)); } }
public List <Category> GetCategories() { using (var context = new CbContext()) { return(context.Categories.ToList()); } }
public List <Order> GetProducts() { using (var context = new CbContext()) { return(context.Orders.ToList()); } }
public List <Category> GetFeaturedCategories() { using (var context = new CbContext()) { return(context.Categories.Where(x => x.isFeatured && x.ImageURL != null).ToList()); } }
public List <tbl_Pincode> GetPincodeByDistrict(int id) { using (var context = new CbContext()) { return(context.tbl_Pincodes.Where(x => x.DistrictId == id).ToList()); } }
public Product GetProductById(int id) { using (var context = new CbContext()) { return(context.Products.Where(x => x.Id == id).Include(x => x.Category).FirstOrDefault()); } }
public Config GetConfig(string Key) { using (var context = new CbContext()) { return(context.Configrations.Find(Key)); } }
public List <tbl_District> GetDistrictByState(int id) { using (var context = new CbContext()) { return(context.tbl_Districts.Where(x => x.StateId == id).ToList()); } }
public List <Product> GetProducts(List <int> IDs) { using (var context = new CbContext()) { return(context.Products.Where(product => IDs.Contains(product.Id)).ToList()); } }
public int GetMaximumPrice() { using (var context = new CbContext()) { return((int)(context.Products.Max(x => x.Price))); } }
public List <Product> GetProductsByCategory(int categoryID, int pageSize) { using (var context = new CbContext()) { return(context.Products.Where(x => x.Category.Id == categoryID).OrderByDescending(x => x.Id).Take(pageSize).Include(x => x.Category).ToList()); } }
public List <Product> GetLatestProducts(int noOfProducts) { using (var context = new CbContext()) { return(context.Products.OrderByDescending(x => x.Id).Take(noOfProducts).Include(x => x.Category).ToList()); } }
public void SaveOrder(Order order) { using (var context = new CbContext()) { context.Orders.Add(order); context.SaveChanges(); } }
public void UpdateCategory(Category category) { using (var context = new CbContext()) { context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void SaveCategory(Category category) { using (var context = new CbContext()) { context.Categories.Add(category); context.SaveChanges(); } }
public void UpdateProduct(Product product) { using (var context = new CbContext()) { context.Entry(product).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public int SaveOrder(Order order) { using (var context = new CbContext()) { context.Orders.Add(order); return(context.SaveChanges()); } }
public void SaveProduct(Product product) { using (var context = new CbContext()) { context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged; context.Products.Add(product); context.SaveChanges(); } }
public void DeleteProduct(int id) { using (var context = new CbContext()) { var productDelete = context.Products.Find(id); context.Products.Remove(productDelete); context.SaveChanges(); } }
public int ShopPageSize() { using (var context = new CbContext()) { var pageSizeConfig = context.Configrations.Find("ShopPageSize"); return(pageSizeConfig != null?int.Parse(pageSizeConfig.Value) : 6); } }
public List <Product> GetProducts(int pageNo) { int pageSize = 5;// int.Parse(ConfigurationsService.Instance.GetConfig("ListingPageSize").Value); using (var context = new CbContext()) { //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 void DeleteCategory(int id) { using (var context = new CbContext()) { var category = context.Categories.Where(x => x.Id == id).Include(x => x.Products).FirstOrDefault(); context.Products.RemoveRange(category.Products); //first delete products of this category context.Categories.Remove(category); context.SaveChanges(); } }
public int GetProductsCount(string search) { using (var context = new CbContext()) { 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?minimumPrice, int?maximumPrice, int?categoryID, int?sortBy) { using (var context = new CbContext()) { 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.Count); } }