Ejemplo n.º 1
0
        public static bool SeedRequired(RecipiDbContext context)
        {
            context.Database.EnsureCreated();
            var t = context.Recipes.OrderByDescending(v => v.Description).FirstOrDefault();

            return(t == null);
        }
Ejemplo n.º 2
0
        // Gimme some non-prod data please
        public static void SeedDummyData(RecipiDbContext context, int numberOfRecipes = 40)
        {
            Random random = new Random();

            // Recipe name pool
            var recipeWord1 = new[] { "Turtle", "Swordfish", "Tofu", "Chicken", "Spectacular", "Bread", "Apple", "Yoghurt" };
            var recipeWord2 = new[] { "Stew", "Cake", "Pie", "Crumble", "Pasta", "Lasaga", "Linguini", "Dessert" };

            // Recipes
            for (int i = numberOfRecipes - 1; i >= 0; i--)
            {
                var w1    = recipeWord1[random.Next(recipeWord1.Length)];
                var w2    = recipeWord2[random.Next(recipeWord2.Length)];
                var steps = new List <Step>();
                for (int j = 0; j < random.Next(5); j++)
                {
                    steps.Add(new Step {
                        Number      = j,
                        Amount      = random.Next(10),
                        Instruction = w1
                    });
                }
                var r = new Recipe {
                    Name  = $"{w1} {w2}",
                    Steps = steps
                };
                context.Recipes.Add(r);
            }
            context.SaveChanges();
        }