public async Task <IActionResult> AddIngredientToRecipe(UpdateRecipeIngredientsInputModel input) { var recipeId = input.Recipe.Id; if (!this.ModelState.IsValid) { input.RecipeIngredients = await this.recipeIngredientsService.GetAllCurrentRecipeAsync <RecipeIngredientViewModel>(recipeId); input.Recipe = await this.recipesService.GetDetailsAsync <RecipeAdminBaseViewModel>(recipeId); return(this.View(input)); } var isAdded = await this.recipeIngredientsService.AddIngredientToRecipeAsync(recipeId, input.Name, input.Quantity); if (!isAdded) { this.TempData["ErrorMessage"] = GlobalConstants.ProblemWithAddingIngredient; } else { this.TempData["InfoMessage"] = GlobalConstants.SuccessAddedMessage; } return(this.RedirectToAction(nameof(this.UpdateRecipeIngredients), new { Id = recipeId })); }
public async Task <IActionResult> UpdateRecipeIngredients(string id) { var model = new UpdateRecipeIngredientsInputModel() { RecipeIngredients = await this.recipeIngredientsService.GetAllCurrentRecipeAsync <RecipeIngredientViewModel>(id), Recipe = await this.recipesService.GetDetailsAsync <RecipeAdminBaseViewModel>(id), }; return(this.View(model)); }