public List <Category> GetCategories(string search, int pageNo) { int pageSize = 3; using (var context = new OgContext()) { 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 OgContext()) { return(context.Categories.Find(ID)); } }
public List <Category> GetFeaturedCategories() { using (var context = new OgContext()) { return(context.Categories.Where(x => x.isFeatured && x.ImageURL != null).ToList()); } }
public List <Product> GetProductsByCategory(int categoryID, int pageSize) { using (var context = new OgContext()) { 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 numberOfProducts) { using (var context = new OgContext()) { return(context.Products.OrderByDescending(x => x.ID).Take(numberOfProducts).Include(x => x.Category).ToList()); } }
public List <Product> GetProducts(string search, int pageNo, int pageSize) { using (var context = new OgContext()) { 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 Config GetConfig(string Key) { using (var context = new OgContext()) { return(context.Configurations.Find(Key)); } }
public List <Product> GetProducts(int pageNo, int pageSize) { using (var context = new OgContext()) { return(context.Products.OrderByDescending(x => x.ID).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList()); } }
public Order GetOrderByID(int ID) { using (var context = new OgContext()) { return(context.Orders.Where(x => x.ID == ID).Include(x => x.OrderItems).Include("OrderItems.Product").FirstOrDefault()); } }
public List <Product> GetProducts(List <int> IDs) { using (var context = new OgContext()) { return(context.Products.Where(product => IDs.Contains(product.ID)).ToList()); } }
public Product GetProduct(int ID) { using (var context = new OgContext()) { return(context.Products.Where(x => x.ID == ID).Include(x => x.Category).FirstOrDefault()); } }
public int GetMaximumPrice() { using (var context = new OgContext()) { return((int)(context.Products.Max(x => x.Price))); } }
public void SaveCategory(Category category) { using (var context = new OgContext()) { context.Categories.Add(category); context.SaveChanges(); } }
public void UpdateProduct(Product product) { using (var context = new OgContext()) { context.Entry(product).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public int SaveOrder(Order order) { using (var context = new OgContext()) { context.Orders.Add(order); return(context.SaveChanges()); } }
public List <Category> GetAllCategories() { using (var context = new OgContext()) { return(context.Categories .ToList()); } }
public void UpdateCategory(Category category) { using (var context = new OgContext()) { context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public int ShopPageSize() { using (var context = new OgContext()) { var pageSizeConfig = context.Configurations.Find("ShopPageSize"); return(pageSizeConfig != null?int.Parse(pageSizeConfig.Value) : 6); } }
public void SaveProduct(Product product) { using (var context = new OgContext()) { 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 OgContext()) { var product = context.Products.Find(ID); context.Products.Remove(product); context.SaveChanges(); } }
public List <Product> GetProducts(int pageNo) { int pageSize = 10;// int.Parse(ConfigurationsService.Instance.GetConfig("ListingPageSize").Value); using (var context = new OgContext()) { 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 OgContext()) { 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 bool UpdateOrderStatus(int ID, string status) { using (var context = new OgContext()) { var order = context.Orders.Find(ID); order.Status = status; context.Entry(order).State = EntityState.Modified; return(context.SaveChanges() > 0); } }
public List <Product> SearchProducts(string searchTerm, int?minimumPrice, int?maximumPrice, int?categoryID, int?sortBy, int pageNo, int pageSize) { using (var context = new OgContext()) { var products = context.Products.ToList(); // var products = new List<Product>(); 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.Skip((pageNo - 1) * pageSize).Take(pageSize).ToList()); } }
public int GetCategoriesCount(string search) { using (var context = new OgContext()) { 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 int GetProductsCount(string search) { using (var context = new OgContext()) { 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 SearchOrdersCount(string userID, string status) { using (var context = new OgContext()) { var orders = context.Orders.ToList(); if (!string.IsNullOrEmpty(userID)) { orders = orders.Where(x => x.UserID.ToLower().Contains(userID.ToLower())).ToList(); } if (!string.IsNullOrEmpty(status)) { orders = orders.Where(x => x.Status.ToLower().Contains(status.ToLower())).ToList(); } return(orders.Count); } }
public List <Order> SearchOrders(string userID, string status, int pageNo, int pageSize) { using (var context = new OgContext()) { var orders = context.Orders.ToList(); if (!string.IsNullOrEmpty(userID)) { orders = orders.Where(x => x.UserID.ToLower().Contains(userID.ToLower())).ToList(); } if (!string.IsNullOrEmpty(status)) { orders = orders.Where(x => x.Status.ToLower().Contains(status.ToLower())).ToList(); } return(orders.Skip((pageNo - 1) * pageSize).Take(pageSize).ToList()); } }