Beispiel #1
0
        // TODO
        // [Route("/Identity/Recipes/All")]
        public IActionResult All(int page = 1)
        {
            var recipes   = this.recipesService.GetAll <ListRecipesCollectionPartailViewModel>(true, GlobalConstants.ItemsPerPage, (page - 1) * GlobalConstants.ItemsPerPage);
            var viewModel = new RecipeAllViewModel {
                Recipes = recipes
            };

            var count = this.recipesService.GetCountOfAllRecipes(true);

            viewModel.PagesCount  = (int)Math.Ceiling((double)count / GlobalConstants.ItemsPerPage);
            viewModel.CurrentPage = page;

            return(this.View(viewModel));
        }
Beispiel #2
0
        public async Task <IActionResult> SearchByAllergens(int[] selected)
        {
            if (selected.Length > 0)
            {
                var matchedRecipes = this.recipeService.GetAllNonContainingByAllergenId(selected);
                var blq            = matchedRecipes.To <RecipeSimpleViewModel>().AsEnumerable();

                var searchedAllergens = await this.allergensService.GetAllToViewModelByIds <AllergenSimpleViewModel>(selected).ToListAsync();

                var recipesViewModel = new RecipeAllViewModel {
                    Recipes = blq, Allergens = searchedAllergens
                };

                return(this.View("SearchResult", recipesViewModel));
            }

            var allergens = this.allergensService.GetAllToViewModel <AllergenSimpleViewModel>().ToList();

            return(this.View(allergens));
        }
Beispiel #3
0
        public async Task <IActionResult> SearchByIngredients(int[] selected)
        {
            if (selected.Length > 0)
            {
                var matchedRecipes = await this.recipeService.GetRecipesByMatchingIngredients(selected).To <RecipeSimpleViewModel>().ToListAsync();

                var searchedIngredients = await this.ingredientService.GetAllToViewModelByIds <RecipeCreateIngredientViewModel>(selected).ToListAsync();

                var recipesViewModel = new RecipeAllViewModel {
                    Recipes = matchedRecipes, Ingredients = searchedIngredients
                };

                return(this.View("SearchResult", recipesViewModel));
            }

            var ingredients = this.ingredientService.GetAllToViewModel <IngredientSearchViewModel>().ToArray();

            SearchByIngredientsInputModel viewModel = new SearchByIngredientsInputModel {
                Ingredients = ingredients
            };

            return(this.View(viewModel));
        }