Ejemplo n.º 1
0
        //Directs to ConfirmSaveRecipe when users click the Save Recipe button. This shows the recipe info
        public async Task <IActionResult> ConfirmSaveRecipe(int id)
        {
            //Regex to remove the html tags from the summary and directions
            var htmlRegEx = "<[^>]*>";
            var userId    = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var recipe    = await _recipeClient.SearchForRecipeById(id);

            var isSavedRecipe = await _repositoryClient.FindSavedRecipe(id, userId);

            var recipeResult = new RecipeConfirmationInfoViewModel()
            {
                Title               = recipe.Title,
                Image               = recipe.Image,
                Id                  = recipe.Id,
                Summary             = Regex.Replace(recipe.Summary ?? "No Summary Available", htmlRegEx, string.Empty),
                Instructions        = Regex.Replace(recipe.Instructions ?? "No Instructions Available", htmlRegEx, string.Empty),
                ExtendedIngredients = recipe.ExtendedIngredients,
                UserSavedRecipe     = isSavedRecipe
            };

            return(View(recipeResult));
        }