Example #1
0
        public async Task <IActionResult> RecipeResults(string SearchString)
        {
            if (String.IsNullOrEmpty(SearchString))
            {
                return(View("RecipeSearch"));
            }

            var response = await _recipePuppyClient.GetRecipes(SearchString);

            //if(response.results.Length==0)
            //{
            //    var model = new RecipeNotFoundViewModel();
            //    model.Ingredients = SearchString;
            //    return View("RecipeNotFound", model);
            //}

            var viewModel = new RecipeResultsViewModel();

            //viewModel.SearchResults = MapSearchesList(SearchString, response);

            viewModel.SearchResults = response.results.
                                      Select(
                result => new Recipe()
            {
                title       = result.title,
                ingredients = result.ingredients,
                thumbnail   = result.thumbnail,
                href        = result.href
            }).ToList();

            viewModel.SearchKeyword = SearchString;

            return(View(viewModel));
        }
Example #2
0
        public async Task <IActionResult> AddToFavorite(string search, int index)
        {
            var response = await _recipePuppyClient.GetRecipes(search);

            var recipeModel = new RecipeResultsViewModel();

            recipeModel.SearchResults = response.results.
                                        Select(
                result => new Recipe()
            {
                title       = result.title,
                ingredients = result.ingredients,
                thumbnail   = result.thumbnail,
                href        = result.href
            }).ToList();

            var faveDAL = new FavoritesDAL();

            faveDAL.Title       = recipeModel.SearchResults[index].title;
            faveDAL.Ingredients = recipeModel.SearchResults[index].ingredients;
            faveDAL.href        = recipeModel.SearchResults[index].href;

            var user = await _userManager.GetUserAsync(User);

            faveDAL.Id = user.Id;

            _applicationDbContext.Favorites.Add(faveDAL);
            _applicationDbContext.SaveChanges();

            //CREATE USERs LIST TO SHOW ON THEIR VIEW
            var viewModel = new FavoritesViewModel();

            viewModel.Favorites = MapFavoritesList(user.Id);

            return(View("Favorites", viewModel));
        }