Ejemplo n.º 1
0
        private StatusCodeResult ValidateRecipe(List <int> authorsId, List <int> categoriesId, List <int> stepsId, List <int> ingredientsId, Recipe recipe)
        {
            recipe.Country = _countryRepository.GetCountry(recipe.Country.Id);

            if (recipe == null || authorsId.Count() <= 0 || categoriesId.Count() <= 0 || stepsId.Count() <= 0 || ingredientsId.Count() <= 0)
            {
                ModelState.AddModelError("", "Missing recipe, author, category, step, ingredient or country");
                return(BadRequest());
            }

            foreach (var id in authorsId)
            {
                if (!_authorRepository.AuthorExists(id))
                {
                    ModelState.AddModelError("", "Author Not Found");
                    return(StatusCode(404));
                }
            }

            foreach (var id in categoriesId)
            {
                if (!_categoryRepository.CategoryExists(id))
                {
                    ModelState.AddModelError("", "Category Not Found");
                    return(StatusCode(404));
                }
            }

            foreach (var id in stepsId)
            {
                if (!_stepRepository.StepExists(id))
                {
                    ModelState.AddModelError("", "Step Not Found");
                    return(StatusCode(404));
                }
            }

            foreach (var id in ingredientsId)
            {
                if (!_ingredientRepository.IngredientExists(id))
                {
                    ModelState.AddModelError("", "Ingredient Not Found");
                    return(StatusCode(404));
                }
            }

            if (!_countryRepository.CountryExists(recipe.Country.Id))
            {
                ModelState.AddModelError("", "Country does not exist");
                return(StatusCode(404));
            }

            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Critical Error");
                return(BadRequest());
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public IActionResult GetStep(int stepId)
        {
            if (!_stepRepository.StepExists(stepId))
            {
                return(NotFound());
            }

            var step = _stepRepository.GetStep(stepId);

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

            var stepDto = new StepDto()
            {
                Id          = step.Id,
                Description = step.Description
            };

            return(Ok(stepDto));
        }