Exemplo n.º 1
0
        public IActionResult GetIngredientssOFRecipe(int recipeId)
        {
            if (!_recipeRepository.RecipeExists(recipeId))
            {
                return(NotFound());
            }

            var ingredients = _ingredientRepository.GetIngredientsOfARecipe(recipeId);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var ingredientsDto = new List <IngredientDto>();

            foreach (var ingredient in ingredients)
            {
                ingredientsDto.Add(new IngredientDto()
                {
                    Id       = ingredient.Id,
                    Name     = ingredient.Name,
                    Quantity = ingredient.Quantity
                });
            }

            return(Ok(ingredientsDto));
        }
Exemplo n.º 2
0
        public IActionResult GetRecipeById(int recipeId)
        {
            var completeRecipeViewModel = new CompleteRecipeViewModel();

            completeRecipeViewModel.ReviewsReviewer = new Dictionary <ReviewDto, ReviewerDto>();

            var recipe = _recipeRepository.GetRecipe(recipeId);

            if (recipe == null)
            {
                ModelState.AddModelError("", "Error retrivieng recipe");
                recipe = new RecipeDto();
            }

            var categories = _categoryRepository.GetAllCategoriesForRecipe(recipeId);

            if (categories.Count() <= 0)
            {
                ModelState.AddModelError("", "Error retrivieng categories");
            }

            var ingredients = _ingredientRepository.GetIngredientsOfARecipe(recipeId);

            if (ingredients.Count() <= 0)
            {
                ModelState.AddModelError("", "Error retrivieng ingredients");
            }

            var steps = _stepRepository.GetStepsForARecipe(recipeId);

            if (steps.Count() <= 0)
            {
                ModelState.AddModelError("", "Error retrivieng steps");
            }

            var authors = _authorRepository.GetAuthorsOfARecipe(recipeId);

            if (authors.Count() <= 0)
            {
                ModelState.AddModelError("", "Error retrivieng authors");
            }

            var reviews = _reviewRepository.GetReviewsOfARecipe(recipeId);

            foreach (var review in reviews)
            {
                var reviewer = _reviewerRepository.GetReviewerOfAReview(review.Id);
                completeRecipeViewModel.ReviewsReviewer.Add(review, reviewer);
            }

            var rating = _recipeRepository.GetRecipeRatingAverage(recipeId);

            var country = _countryRepository.GetCountryOfARecipe(recipeId);

            completeRecipeViewModel.Recipe      = recipe;
            completeRecipeViewModel.Categories  = categories;
            completeRecipeViewModel.Ingredients = ingredients;
            completeRecipeViewModel.Steps       = steps;
            completeRecipeViewModel.Rating      = rating;
            completeRecipeViewModel.Country     = country;
            completeRecipeViewModel.Authors     = authors;

            if (!ModelState.IsValid)
            {
                ViewBag.ViewMessage = "There was an error with getting the recipe";
            }
            return(View(completeRecipeViewModel));
        }