示例#1
0
        public List <RecipeAng> GenerateRecipeListFromCocktailIds(List <int> cocktailIds)
        {
            var result = new List <RecipeAng>();

            foreach (var id in cocktailIds)
            {
                var cocktailRecipeToAdd = new RecipeAng();
                var cocktail            = _cocktailRepo.GetCocktailById(id);
                cocktailRecipeToAdd.CocktailName = cocktail.Name;
                cocktailRecipeToAdd.ImgUrl       = "/Content/img/" + cocktail.ImgUrl + ".jpg";

                //get all ingredients
                var ingredients = _ciRepo.GetAllIngredientsByCocktailId(id);
                foreach (var ing in ingredients)
                {
                    cocktailRecipeToAdd.Ingredients.Add
                        (ing.Amount + " " + _ingredientRepo.GetIngredientById(ing.IngredientId).Name);
                }

                //get all recipe steps
                cocktailRecipeToAdd.RecipeSteps =
                    _recipeRepo.GetAllRecipeStepsByCocktail(id).Select(m => m.StepNumber + ". " + m.Text).ToList();

                //add recipe to the model
                result.Add(cocktailRecipeToAdd);
            }

            return(result.OrderBy(m => m.Ingredients.Count).ToList());
        }
        public ActionResult GetResults(int id)
        {
            var model = new ResultGetResultsViewModel();

            var filteredCocktails = _ciRepo.GetAllCocktailIngredients()
                                    .Where(m => m.IngredientId == id);

            //get a list of unique cocktails
            var cocktails = new List <Cocktail>();

            foreach (var item in filteredCocktails)
            {
                var name = _cocktailRepo.GetCocktailById(item.CocktailId).Name;
                if (!cocktails.Any(m => m.Name == name))
                {
                    cocktails.Add(_cocktailRepo.GetCocktailById(item.CocktailId));
                }
            }

            //add each cocktail to the VM list
            foreach (var item in cocktails)
            {
                var ingredients     = _ciRepo.GetAllIngredientsByCocktailId(id).Select(m => m.CocktailId);
                var ingredientNames = new List <string>();
                foreach (var num in ingredients)
                {
                    ingredientNames.Add(_ingredientRepo.GetIngredientById(num).Name);
                }

                model.Cocktails.Add(new ResultGetResultsCocktails
                {
                    Name        = item.Name,
                    RecipeLink  = item.ImgUrl,
                    Ingredients = ingredientNames
                });
            }

            return(View(model));
        }
示例#3
0
        public void CanGetIngredientById()
        {
            var ingredient = _repo.GetIngredientById(1);

            Assert.AreEqual(ingredient.Name, "Coca Cola");
        }
示例#4
0
        public Ingredient GetIngredientById(int ingredientId)
        {
            var ingredient = _ingredientsRepository.GetIngredientById(ingredientId);

            return(ingredient);
        }
示例#5
0
 public async Task <Ingredient> GetIngredientById(long id)
 {
     _logger.Debug("Calling Get Ingredient By ID");
     return(await _ingredientRepository.GetIngredientById(id));
 }