Ejemplo n.º 1
0
        public Recipe Save(CreateRecipeRequestDto body)
        {
            var author = _authorService.Find(body.AuthorId);

            if (author == null)
            {
                throw new AuthorNotFoundException(body.AuthorId);
            }

            if (body.Ingredients.Any(x => x.Id == null))
            {
                throw new InvalidIngredientsException();
            }

            var fullIngredients = _ingredientService.FindAllByIds(body.Ingredients.Select(x => x.Id));

            var insertedRecipe = _recipeService.Save(
                Recipe.Create(
                    body.Name,
                    body.Description,
                    author,
                    body.Ingredients,
                    fullIngredients,
                    body.Steps)
                );

            return(insertedRecipe);
        }
 public RecipeResponseDto CreateRecipe([FromBody] CreateRecipeRequestDto body)
 {
     return(_recipeService.Save(body));
 }