コード例 #1
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
 public Product GetProduct(int id)
 {
     using (var _context = new EcartContext())
     {
         return(_context.Products.Where(p => p.Id == id).Include(c => c.Category).FirstOrDefault());
     }
 }
コード例 #2
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
 public List <Product> GetProduct(List <int> ids)
 {
     using (var _context = new EcartContext())
     {
         return(_context.Products.Where(p => ids.Contains(p.Id)).ToList());
     }
 }
コード例 #3
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
 public int GetMaximumPrice()
 {
     using (var context = new EcartContext())
     {
         return((int)(context.Products.Max(x => x.UnitPrice)));
     }
 }
コード例 #4
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
 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());
         }
     }
 }
コード例 #5
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
 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());
     }
 }
コード例 #6
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
 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());
     }
 }
コード例 #7
0
 public List <Config> GetConfigurations()
 {
     using (var _context = new EcartContext())
     {
         return(_context.Configurations.ToList());
     }
 }
コード例 #8
0
 public Config GetConfig(string key)
 {
     using (var _context = new EcartContext())
     {
         return(_context.Configurations.Single(x => x.Key == key));
     }
 }
コード例 #9
0
ファイル: CategoriesService.cs プロジェクト: ikhuram/Ecart
 public List <Category> GetFeaturedCategories()
 {
     using (var _context = new EcartContext())
     {
         return(_context.Categories.Where(c => c.IsFeatured).Take(4).ToList());
     }
 }
コード例 #10
0
ファイル: CategoriesService.cs プロジェクト: ikhuram/Ecart
 public Category GetCategory(int id)
 {
     using (var _context = new EcartContext())
     {
         return(_context.Categories.Single(x => x.Id == id));
     }
 }
コード例 #11
0
ファイル: CategoriesService.cs プロジェクト: ikhuram/Ecart
 public List <Category> GetCategories()
 {
     using (var _context = new EcartContext())
     {
         return(_context.Categories.ToList());
     }
 }
コード例 #12
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
 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());
     }
 }
コード例 #13
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
 public List <Product> GetProducts()
 {
     using (var _context = new EcartContext())
     {
         return(_context.Products.Include(p => p.Category).ToList());
     }
 }
コード例 #14
0
 public void Edit(Config config)
 {
     using (var _context = new EcartContext())
     {
         _context.Entry(config).State = System.Data.Entity.EntityState.Modified;
         _context.SaveChanges();
     }
 }
コード例 #15
0
 public void Create(Config config)
 {
     using (var _context = new EcartContext())
     {
         _context.Configurations.Add(config);
         _context.SaveChanges();
     }
 }
コード例 #16
0
ファイル: CategoriesService.cs プロジェクト: ikhuram/Ecart
 public void Create(Category category)
 {
     using (var _context = new EcartContext())
     {
         _context.Categories.Add(category);
         _context.SaveChanges();
     }
 }
コード例 #17
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
 public void Update(Product product)
 {
     using (var _context = new EcartContext())
     {
         _context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         _context.SaveChanges();
     }
 }
コード例 #18
0
        public int ShopPageSize()
        {
            using (var context = new EcartContext())
            {
                var pageSizeConfig = context.Configurations.Find("ShopPageSize");

                return(pageSizeConfig != null?int.Parse(pageSizeConfig.Value) : 8);
            }
        }
コード例 #19
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
        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());
            }
        }
コード例 #20
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
        public void Delete(int id)
        {
            using (var _context = new EcartContext())
            {
                var product = _context.Products.Find(id);

                _context.Products.Remove(product);
                _context.SaveChanges();
            }
        }
コード例 #21
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
        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();
            }
        }
コード例 #22
0
        public void Delete(string key)
        {
            using (var _context = new EcartContext())
            {
                var config = _context.Configurations.Find(key);

                _context.Configurations.Remove(config);
                _context.SaveChanges();
            }
        }
コード例 #23
0
ファイル: CategoriesService.cs プロジェクト: ikhuram/Ecart
        public void Delete(int id)
        {
            using (var _context = new EcartContext())
            {
                var category = _context.Categories.Find(id);

                _context.Categories.Remove(category);
                _context.SaveChanges();
            }
        }
コード例 #24
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
 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());
         }
     }
 }
コード例 #25
0
ファイル: ProductsService.cs プロジェクト: ikhuram/Ecart
        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);
            }
        }