コード例 #1
0
        public async Task <IActionResult> RemoveRecipeActionPost(string id, string recipeActionId)
        {
            var recipe = await _recipeManager.GetRecipe(id, _userManager.GetUserId(User));

            if (recipe == null)
            {
                return(GetNotFoundActionResult());
            }

            RecipeAction recipeAction = null;

            if (!string.IsNullOrEmpty(recipeActionId))
            {
                recipeAction = recipe.RecipeActions.SingleOrDefault(action => action.Id == recipeActionId);
                if (recipeAction == null)
                {
                    return(GetNotFoundActionResult());
                }
            }

            await _recipeManager.RemoveRecipeAction(recipeActionId);

            return(RedirectToAction("EditRecipe", "Recipes", new
            {
                id,
                statusMessage = new StatusMessageModel()
                {
                    Message = $"Recipe Action removed",
                    Severity = StatusMessageModel.StatusSeverity.Success
                }.ToString()
            }));
        }