コード例 #1
0
        public List<Product> Select(String searchString, int idTag, int categoryId)
        {
            using (var dbContext = new DataContext())
            {
                var products = new List<Product>();

                if (idTag != 0)
                    products = dbContext.Tags.Include("Products").FirstOrDefault(x => x.TagId == idTag).Products.ToList();
                if (!String.IsNullOrEmpty(searchString))
                    products = dbContext.Products.Where(s => s.Name.ToLower().Contains(searchString.ToLower())).ToList();
                if (categoryId != 0)
                {
                    var listCategory = new CategoryRepository().Select(categoryId);
                    if (new CategoryRepository().IsParentCategory(categoryId))
                    {
                        var category = new List<Category>();
                        foreach (var item in listCategory)
                        {
                            var categories = new CategoryRepository().Select(item.CategoryId);
                            category = category.Concat(categories).ToList();
                            categories.Clear();
                        }
                        listCategory.Clear();
                        listCategory = listCategory.Concat(category).ToList();
                    }

                    foreach (var item in listCategory)
                    {
                        var product = dbContext.Products.Where(s => s.CategoryId == item.CategoryId).ToList();
                        products = products.Concat(product).ToList();
                        product.Clear();
                    }
                }

                return products;
            }
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: Natashka92/OzonShop
 //
 // GET: /Home/MenuCategory
 public ActionResult MenuCategory(int parentId)
 {
     var catigories = new CategoryRepository().Select(parentId);
     return PartialView(catigories);
 }