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()); }
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()); }
public async Task <ActionResult <RecipeDto[]> > GetAllRecipes(string name = null) { var recipes = await repository.GetAllRecipesAsync(name); return(mapper.Map <RecipeDto[]>(recipes)); }
public async Task <IActionResult> OnGet() { Recipes = await repository.GetAllRecipesAsync(SearchTerm); return(Page()); }