コード例 #1
0
        public async Task <IActionResult> OnGet(int productId)
        {
            Product = await repository.GetProductAsync(productId);

            if (Product == null)
            {
                return(RedirectToPage("./NotFound"));
            }

            var recipes = await repository.GetAllRecipesAsync();

            var recipesWithThisProduct = recipes.Where(r => r.Ingredients.Any(p => p.Product.Name == Product.Name));

            Recipes = mapper.Map <RecipeDto[]>(recipesWithThisProduct);

            return(Page());
        }
コード例 #2
0
        public async Task <IActionResult> OnGet()
        {
            var recipes = await repository.GetAllRecipesAsync();

            if (recipes.Length > 3)
            {
                var recentRecipes = recipes.TakeLast(3).ToArray();

                //var lastThreeRecipes = new Recipe[] {
                //    recipes[recipes.Length - 1],
                //    recipes[recipes.Length - 2],
                //    recipes[recipes.Length - 3]
                //};
                Recipes = mapper.Map <RecipeDto[]>(recentRecipes);
            }
            else
            {
                Recipes = mapper.Map <RecipeDto[]>(recipes);
            }


            return(Page());
        }
コード例 #3
0
        public async Task <ActionResult <RecipeDto[]> > GetAllRecipes(string name = null)
        {
            var recipes = await repository.GetAllRecipesAsync(name);

            return(mapper.Map <RecipeDto[]>(recipes));
        }
コード例 #4
0
        public async Task <IActionResult> OnGet()
        {
            Recipes = await repository.GetAllRecipesAsync(SearchTerm);

            return(Page());
        }