Пример #1
0
        public void MigrateAndSeedData()
        {
            if (Database.GetPendingMigrations().Any())
            {
                Database.Migrate();
            }

            if (!Programs.Any())
            {
                ////Seed database here
                var exercises = new[]
                {
                    new Exercise
                    {
                        Name         = "Squat",
                        Description  = "Bøj i benene",
                        IsRepetition = true,
                        Repetitions  = 12,
                        Sets         = 3
                    },
                    new Exercise
                    {
                        Name         = "Dødløft",
                        Description  = "Hold ryggen rat",
                        IsRepetition = true,
                        Repetitions  = 12,
                        Sets         = 3
                    },
                };

                Exercises.AddRange(exercises);
                SaveChanges();


                var programs = new Program[]
                {
                    new Program()
                    {
                        Name       = "Monday mingle",
                        CreateDate = DateTime.Now,
                        Category   = "Ben",
                        Creater    = "The mighty Thor"
                    },
                    new Program()
                    {
                        Name       = "Tuesday madness",
                        CreateDate = DateTime.Now,
                        Category   = "´Cardio",
                        Creater    = "The mighty Thor"
                    },
                    new Program()
                    {
                        Name       = "Lazy saturday",
                        CreateDate = DateTime.Now,
                        Category   = "Arme",
                        Creater    = "The viking warrior"
                    },
                };
                Programs.AddRange(programs);

                SaveChanges();
                var programExercises = new List <ProgramExercise>();

                foreach (var program in programs)
                {
                    var programExercise = new ProgramExercise()
                    {
                        Program = program,

                        Exercise = exercises.FirstOrDefault()
                    };
                    programExercises.Add(programExercise);
                }

                ProgramExercises.AddRange(programExercises);

                SaveChanges();
            }
        }