Exemplo n.º 1
0
        public async Task <IActionResult> SaveRecipe(RecipeConfirmationInfoViewModel recipeInfo)
        {
            try
            {
                var userId        = User.FindFirstValue(ClaimTypes.NameIdentifier);
                var recipeIsSaved = await _repositoryClient.SaveRecipe(recipeInfo.Id, userId);

                if (recipeIsSaved)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(RedirectToAction("Error", "Home"));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
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));
        }