コード例 #1
0
ファイル: CookyMgmtDdContext.cs プロジェクト: m1sha/GitHubSvn
        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 }
                    });
            }
        }
コード例 #2
0
ファイル: ViewContext.cs プロジェクト: m1sha/GitHubSvn
 public void AddRecipe(RecipeView recipeView)
 {
     DbRecipe dbRecipe = new DbRecipe(recipeView);
     _context.AddRecipe(dbRecipe, recipeView.Ingredients.Select(p => new DbIngredient(p)).ToArray());
 }