コード例 #1
0
        public void CanAddCocktail()
        {
            var addedCocktail = _cocktailRepo.AddCocktail(Mocks.mockCocktail);

            Assert.AreEqual(_cocktailRepo.GetAllCocktails().Count, 7);
            Assert.AreEqual(addedCocktail.CocktailId, 7);
        }
コード例 #2
0
        public ActionResult Cocktails(AdminCocktailsVM model)
        {
            if (ModelState.IsValid)
            {
                //add cocktail data to cocktail table
                var cocktailAdded = _cocktailRepo.AddCocktail(new Cocktail
                {
                    Name   = model.Name,
                    ImgUrl = model.ImgUrl
                });

                //add cocktail/ingredient combo data to that table
                foreach (var ingredient in model.SelectedIngredients)
                {
                    _ciRepo.AddCocktailIngredient(new CocktailIngredient
                    {
                        CocktailId   = cocktailAdded.CocktailId,
                        IngredientId = ingredient.Id,
                        Amount       = ingredient.Amount
                    });
                }

                //add recipe data to recipe table
                foreach (var step in model.RecipeSteps)
                {
                    _recipeRepo.AddRecipe(new Recipe
                    {
                        CocktailId = cocktailAdded.CocktailId,
                        StepNumber = step.RecipeStepNumber,
                        Text       = step.Text
                    });
                }

                //redirect to admin home
                return(View("Index"));
            }

            //otherwise something went wrong, send back to view
            return(View(model));
        }