Example #1
0
 public List <Category> ListCategory()
 {
     using (var context = new DescoContext())
     {
         return(context.Categories.ToList());
     }
 }
Example #2
0
        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());
                }
            }
        }
Example #3
0
 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());
     }
 }
Example #4
0
 public List <Category> ListFeaturedCategory()
 {
     using (var context = new DescoContext())
     {
         return(context.Categories.Where(x => x.isFeatured == true).ToList());
     }
 }
Example #5
0
 public List <Product> GetProducts(List <int> Id)
 {
     using (var context = new DescoContext())
     {
         return(context.Product.Where(x => Id.Contains(x.Id)).ToList());
     }
 }
Example #6
0
 public int GetMaximumPrice()
 {
     using (var context = new DescoContext())
     {
         return((int)(context.Product.Max(x => x.Price)));
     }
 }
Example #7
0
 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());
         }
     }
 }
Example #8
0
 public Category FindCategory(int Id)
 {
     using (var context = new DescoContext())
     {
         return(context.Categories.Find(Id));
     }
 }
Example #9
0
 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());
     }
 }
Example #10
0
 public Config FindConfiguration(string key)
 {
     using (var context = new DescoContext())
     {
         return(context.Configurations.Find(key));
     }
 }
Example #11
0
 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());
     }
 }
Example #12
0
 public void UpdateCategory(Category category)
 {
     using (var context = new DescoContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Example #13
0
 public void CreateCategory(Category category)
 {
     using (var context = new DescoContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
Example #14
0
        public ActionResult Details(int Id)
        {
            DescoContext context = new DescoContext();

            DetailProductViewMdodel model = new DetailProductViewMdodel();

            model.Product = productfunctions.FindProduct(context, Id);
            return(View(model));
        }
Example #15
0
 public void DeleteProduct(int Id)
 {
     using (var context = new DescoContext())
     {
         var p = context.Product.Find(Id);
         context.Product.Remove(p);
         context.SaveChanges();
     }
 }
Example #16
0
 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();
     }
 }
Example #17
0
 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();
     }
 }
Example #18
0
 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());
     }
 }
Example #19
0
 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());
         }
     }
 }
Example #20
0
 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());
         }
     }
 }
Example #21
0
        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));
        }
Example #22
0
        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);
            }
        }
Example #23
0
        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"));
            }
        }
Example #24
0
 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();
 }
Example #25
0
 public Product FindProduct(DescoContext context, int Id)
 {
     return(context.Product.Find(Id));
 }