[HttpPost] public async Task Post(RecipeDto recipeDto) { var recipe = new Recipe(); var ingredientRecipes = new List(); foreach (var ingredient in recipeDto.ListOfIngredients) { var ingr = mapper.Map(ingredient); ingr.Ingredient.Id = await context.Ingredients .Where(x => x.Id == ingredient.Ingredient.Id) .Select(x => x.Id) .FirstOrDefaultAsync(); ingredientRecipes.Add(ingr); } recipe.ListOfIngredients = ingredientRecipes; context.Recipes.Add(recipe); await context.SaveChangesAsync(); return new OkResult(); }