コード例 #1
0
        public async Task <IActionResult> Select(string sortType, string recipeName, Category category, int?time, int?rating)
        {
            RecipesMainVM mainVM  = new RecipesMainVM();
            List <Recipe> recipes = _appDb.Recipes.Where(r => r.RecipeName != null).ToList();

            switch (sortType)
            {
            case "latest":
                recipes = _searchServices.searchLatest(recipeName, category, time, rating);
                break;

            case "popular":
                recipes = _searchServices.searchPopular(recipeName, category, time, rating);
                break;

            case "liked":
                var user = await _userManager.GetUserAsync(User);

                recipes = _searchServices.searchLiked(recipeName, category, time, rating, user);
                break;
            }

            mainVM.Recipes = recipes;

            foreach (var recipe in mainVM.Recipes)
            {
                recipe.Sender = await _userManager.FindByIdAsync(recipe.UserId);
            }

            mainVM.selectedCategory = category;
            mainVM.selectedTime     = time;
            mainVM.selectedRating   = rating;

            return(View("RecipesSelect", mainVM));
        }