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

            var steps = _stepRepository.GetStepsForARecipe(recipeId);

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

            var stepsDto = new List <StepDto>();

            foreach (var step in steps)
            {
                stepsDto.Add(new StepDto()
                {
                    Id          = step.Id,
                    Description = step.Description
                });
            }

            return(Ok(stepsDto));
        }
Ejemplo 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));
        }