예제 #1
0
        private void Seed()
        {
            using var context = new RecAPIContext(ContextOptions);
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            var fusilli = new Ingredient
            {
                Id   = 1,
                Name = "Fusilli",
                RecipeIngredients = new List <RecipeIngredient>()
            };

            var garlic = new Ingredient
            {
                Id   = 2,
                Name = "Garlic",
                RecipeIngredients = new List <RecipeIngredient>()
            };

            var fugu = new Ingredient
            {
                Id   = 3,
                Name = "Fugu",
                RecipeIngredients = new List <RecipeIngredient>()
            };

            var recipe = new Recipe
            {
                Id                = 1,
                Name              = "Pure Garlic",
                Description       = "For the true fans of garlic",
                Instructions      = "Peel garlic. Consume garlic.",
                RecipeIngredients = new List <RecipeIngredient>()
            };

            var riGarlic = new RecipeIngredient
            {
                IngredientId = 1,
                Ingredient   = garlic,
                RecipeId     = 1,
                Recipe       = recipe,
                Amount       = 1000,
                Unit         = (Unit)5
            };

            garlic.RecipeIngredients.Add(riGarlic);

            context.Ingredients.Add(garlic);
            context.Ingredients.Add(fusilli);
            context.Ingredients.Add(fugu);
            context.SaveChanges();
        }
예제 #2
0
        private void Seed()
        {
            using var context = new RecAPIContext(ContextOptions);
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            var garlic = new Ingredient
            {
                Id   = 1,
                Name = "Garlic",
                RecipeIngredients = new List <RecipeIngredient>()
            };
            var fusilli = new Ingredient
            {
                Id   = 2,
                Name = "Fusilli",
                RecipeIngredients = new List <RecipeIngredient>()
            };

            var ketchup = new Ingredient
            {
                Id   = 3,
                Name = "Ketchup",
                RecipeIngredients = new List <RecipeIngredient>()
            };

            var recipe = new Recipe
            {
                Id                = 1,
                Name              = "Pasta with garlic",
                Description       = "Garlic is tasty. Fusilli is screw-shaped.",
                Instructions      = "Boil pasta. Add all of the cloves of garlic.",
                RecipeIngredients = new List <RecipeIngredient>()
            };

            var riGarlic = new RecipeIngredient
            {
                RecipeId     = recipe.Id,
                Recipe       = recipe,
                IngredientId = garlic.Id,
                Ingredient   = garlic,
                Amount       = 200,
                Unit         = (Unit)1
            };

            var riFusilli = new RecipeIngredient
            {
                RecipeId     = recipe.Id,
                Recipe       = recipe,
                IngredientId = fusilli.Id,
                Ingredient   = fusilli,
                Amount       = 200,
                Unit         = (Unit)1
            };

            recipe.RecipeIngredients.Add(riGarlic);
            recipe.RecipeIngredients.Add(riFusilli);
            garlic.RecipeIngredients.Add(riGarlic);
            fusilli.RecipeIngredients.Add(riFusilli);

            context.Ingredients.Add(ketchup);
            context.Recipes.Add(recipe);
            context.SaveChanges();
        }