Пример #1
0
        public ActionResult ShowSearchResult(string searchRecipeName, string searchCategoryName, string searchIngridientName)
        {
            SearchViewModel model = new SearchViewModel();

            model.RecipeModel = new ShortRecipeViewModel();
            List <RecipeView> recipes = _recipeProvider.GetRecipes();

            model.Header = "";
            IEnumerable <RecipeView> recipesR = null;
            IEnumerable <RecipeView> recipesC = null;
            IEnumerable <RecipeView> recipesI = null;

            if (!string.IsNullOrEmpty(searchRecipeName))
            {
                recipesR     = _recipeProvider.GetRecipesByRecipeName(searchRecipeName);
                model.Header = model.Header + "Searching \"" + searchRecipeName + "\" in Recipes \n";
            }
            if (!string.IsNullOrEmpty(searchCategoryName))
            {
                recipesC     = _recipeProvider.GetRecipesByCategoryName(searchCategoryName);
                model.Header = model.Header + "Searching \"" + searchCategoryName + "\" in Categories \n";
            }
            if (!string.IsNullOrEmpty(searchIngridientName))
            {
                recipesI     = _recipeProvider.GetRecipesByIngridientName(searchIngridientName);
                model.Header = model.Header + "Searching \"" + searchIngridientName + "\" in Ingridients \n";
            }

            if (recipesR == null && recipesC == null && recipesI == null)
            {
                model.RecipeModel.Recipes = null;
            }
            else
            {
                if (recipesR != null)
                {
                    recipes.RemoveAll(r1 => recipesR.FirstOrDefault(r2 => r2.RecipeId == r1.RecipeId) == null);
                }

                if (recipesC != null)
                {
                    recipes.RemoveAll(r1 => recipesC.FirstOrDefault(r2 => r2.RecipeId == r1.RecipeId) == null);
                }

                if (recipesI != null)
                {
                    recipes.RemoveAll(r1 => recipesI.FirstOrDefault(r2 => r2.RecipeId == r1.RecipeId) == null);
                }

                model.RecipeModel.Recipes = recipes;
            }

            return(PartialView("_SearchResult", model));
        }