コード例 #1
0
        public ActionResult Index(string searchString)
        {
            string category   = null;
            Guid?  categoryId = null;

            if (Request.Form["categories.categories"] != null)
            {
                category = Request.Form["categories.categories"].ToString();
                if (!String.IsNullOrEmpty(category))
                {
                    categoryId = new Guid(category);
                }
            }


            ProductsDTO products;

            if (String.IsNullOrEmpty(searchString))
            {
                if (!categoryId.HasValue)
                {
                    products = ProductLogic.AllProducts();
                }
                else
                {
                    products = ProductLogic.AllProductsInCategory(new Guid(categoryId.ToString()));
                }
            }
            else
            {
                if (!categoryId.HasValue)
                {
                    products = ProductLogic.AllProductsInSearch(searchString);
                }
                else
                {
                    products = ProductLogic.AllProductsInSearchAndCategory(searchString, new Guid(categoryId.ToString()));
                }
            }

            ProductFilters productFilters = new ProductFilters
            {
                productsDTOs = products,
                categories   = CategoryLogic.AllCategories()
            };

            return(View(productFilters));
        }