Exemplo n.º 1
0
        public IActionResult Index(RecipeInfoViewModel recipeInfoViewModel)
        {
            if (ModelState.IsValid)
            {
                var recipeInfo = new RecipeInfo()
                {
                    Title       = recipeInfoViewModel.RecipeInfo.Title,
                    Description = recipeInfoViewModel.RecipeInfo.Description,
                    ImageUrl    = recipeInfoViewModel.RecipeInfo.ImageUrl
                };
                _recipeInfoRepository.AddRecipeInfo(recipeInfo);

                if (recipeInfoViewModel.RecipeList == null || recipeInfoViewModel.RecipeList.Count < 1)
                {
                    return(RedirectToAction("RecipeInfoSaved"));
                }

                var recipeList = new List <Recipe>();
                foreach (var r in recipeInfoViewModel.RecipeList)
                {
                    var recipe = new Recipe()
                    {
                        Name             = r.Name,
                        LongDescription  = r.LongDescription,
                        ShortDescription = r.ShortDescription,
                        PiecesOfJobs     = r.PiecesOfJobs,
                    };
                    recipeList.Add(recipe);
                }

                _recipeRepository.AddRecipeList(recipeList);

                return(RedirectToAction("RecipeInfoSaved"));
            }
            else
            {
                return(View(recipeInfoViewModel));
            }
        }