public List <Category> ListCategory() { using (var context = new DescoContext()) { return(context.Categories.ToList()); } }
public List <Category> ListCategory(string search, int pageNo) { int pageSize = 5; using (var context = new DescoContext()) { if (string.IsNullOrEmpty(search) == false) { 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 List <Product> LatestProduct(int numberOfProducts) { using (var context = new DescoContext()) { return(context.Product.OrderByDescending(x => x.Id).Take(numberOfProducts).Include(x => x.Category).ToList()); } }
public List <Category> ListFeaturedCategory() { using (var context = new DescoContext()) { return(context.Categories.Where(x => x.isFeatured == true).ToList()); } }
public List <Product> GetProducts(List <int> Id) { using (var context = new DescoContext()) { return(context.Product.Where(x => Id.Contains(x.Id)).ToList()); } }
public int GetMaximumPrice() { using (var context = new DescoContext()) { return((int)(context.Product.Max(x => x.Price))); } }
public List <Product> ListProduct(string search, int pageNo, int pageSize) { using (var context = new DescoContext()) { if (string.IsNullOrEmpty(search) == false) { return(context.Product.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.Product .OrderBy(x => x.Id) .Skip((pageNo - 1) * pageSize) .Take(pageSize) .Include(x => x.Category) .ToList()); } } }
public Category FindCategory(int Id) { using (var context = new DescoContext()) { return(context.Categories.Find(Id)); } }
public List <Product> OtherProduct(int pageNo, int pageSize) { using (var context = new DescoContext()) { return(context.Product.OrderByDescending(x => x.Id).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList()); } }
public Config FindConfiguration(string key) { using (var context = new DescoContext()) { return(context.Configurations.Find(key)); } }
public List <Product> ListProduct(int pageNo) { using (var context = new DescoContext()) { int pageSize = 5; return(context.Product.OrderBy(x => x.Id).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList()); } }
public void UpdateCategory(Category category) { using (var context = new DescoContext()) { context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void CreateCategory(Category category) { using (var context = new DescoContext()) { context.Categories.Add(category); context.SaveChanges(); } }
public ActionResult Details(int Id) { DescoContext context = new DescoContext(); DetailProductViewMdodel model = new DetailProductViewMdodel(); model.Product = productfunctions.FindProduct(context, Id); return(View(model)); }
public void DeleteProduct(int Id) { using (var context = new DescoContext()) { var p = context.Product.Find(Id); context.Product.Remove(p); context.SaveChanges(); } }
public void CreateProduct(Product product) { using (var context = new DescoContext()) { context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged; context.Product.Add(product); context.SaveChanges(); } }
public void DeleteCategory(int Id) { using (var context = new DescoContext()) { var p = context.Categories.Where(x => x.Id == Id).Include(x => x.Products).FirstOrDefault(); context.Product.RemoveRange(p.Products); context.Categories.Remove(p); context.SaveChanges(); } }
public List <Product> RelatedProducts(int categoryId, int pageSize) { using (var context = new DescoContext()) { return(context.Product .Where(x => x.Category.Id == categoryId) .OrderByDescending(x => x.Id) .Take(pageSize) .Include(x => x.Category) .ToList()); } }
public int GetCategoryCount(string search) { using (var context = new DescoContext()) { if (string.IsNullOrEmpty(search) == false) { return(context.Categories.Where(category => category.Name != null && category.Name.ToLower().Contains(search.ToLower())).Count()); } else { return(context.Categories.Count()); } } }
public int GetProductCount(string search)//Product Count in Integer { using (var context = new DescoContext()) { if (string.IsNullOrEmpty(search) == false) { return(context.Product.Where(product => product.Name != null && product.Name.ToLower().Contains(search.ToLower())) .Count()); } else { return(context.Product.Count()); } } }
public ActionResult Edit(int Id) { DescoContext context = new DescoContext(); EditProductViewMdodel model = new EditProductViewMdodel(); var product = productfunctions.FindProduct(context, Id); model.Id = product.Id; model.Name = product.Name; model.Description = product.Description; model.Price = product.Price; model.CategoryId = product.Category != null ? product.Category.Id : 0; model.ImageURL = product.ImageURL; model.AvailableCategories = categoryfunctions.ListCategory(); return(PartialView(model)); }
public int ProductsCountPager(string searchTerm, int?minimumPrice, int?maximumPrice, int?categoryId, int?sortBy) { using (var context = new DescoContext()) { var products = context.Product.ToList(); if (categoryId.HasValue) { products = products.Where(x => x.Category.Id == categoryId).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; case 4: products = products.OrderByDescending(x => x.Price).ToList(); break; default: products = products.OrderByDescending(x => x.Id).ToList(); break; } } return(products.Count); } }
public ActionResult Edit(EditProductViewMdodel model) { using (var desoContext = new DescoContext()) { var product = productfunctions.FindProduct(desoContext, model.Id); product.Name = model.Name; product.Description = model.Description; product.Price = model.Price; product.Category = categoryfunctions.FindCategory(model.CategoryId); if (!string.IsNullOrEmpty(model.ImageURL)) { product.ImageURL = model.ImageURL; } productfunctions.UpdateProduct(desoContext, product); return(RedirectToAction("ProductList")); } }
public void UpdateProduct(DescoContext context, Product product) { context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged; context.Entry(product).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); }
public Product FindProduct(DescoContext context, int Id) { return(context.Product.Find(Id)); }