public void AddRecipe(DbRecipe dbRecipe, DbIngredient[] ingredients) { int recipeId = InvokeCommand<int>("INSERT INTO [recipe] ([name], [text]) VALUES (@Name, @Text); SELECT @@IDENTITY;", new[] { new DbCommandParameter { ParameterName = "@Name", Value = dbRecipe.Name }, new DbCommandParameter { ParameterName = "@Text", Value = dbRecipe.Text }, }); foreach (DbIngredient ingredient in ingredients) { InvokeCommand("INSERT INTO [ingredient] ([product_id], [recipe_id]) VALUES(@productId, @recipeId)", new[] { new DbCommandParameter { ParameterName = "@productId", Value = ingredient.ProductId }, new DbCommandParameter { ParameterName = "@recipeId", Value = recipeId } }); } }
public void AddRecipe(RecipeView recipeView) { DbRecipe dbRecipe = new DbRecipe(recipeView); _context.AddRecipe(dbRecipe, recipeView.Ingredients.Select(p => new DbIngredient(p)).ToArray()); }