Exemple #1
0
        public static void Initializer(ForumContext context)
        {
            context.Database.EnsureCreated();

            //Look for any Users.
            if (context.User.Any())
            {
                return;   // DB has been seeded
            }

            var users = new User[]
            {
                new User {
                    Name = "Shawna"
                },
                new User {
                    Name = "Ivy"
                },
                new User {
                    Name = "Mikhail"
                }
            };

            foreach (User u in users)
            {
                context.User.Add(u);
            }
            context.SaveChanges();

            var forums = new ForumPosts[]
            {
                new ForumPosts {
                    PostTopic = "Lighting", PostText = "The idea about using a lace curtain to defuse natural lighting is genius!", Name = new User {
                        Name = "Shawna"
                    }, Date = DateTime.Parse("2020-11-10"), PostRating = 5
                },
                new ForumPosts {
                    PostTopic = "Reframing", PostText = "I didn't understand reframing.", Name = new User {
                        Name = "Ivy"
                    }, Date = DateTime.Parse("2020-7-16"), PostRating = 1
                },
                new ForumPosts {
                    PostTopic = "Golden Hour", PostText = "This definitely gives me a reason to be up early.", Name = new User {
                        Name = "Mikhail"
                    }, Date = DateTime.Parse("2021-1-3"), PostRating = 4
                }
            };

            foreach (ForumPosts f in forums)
            {
                context.ForumPosts.Add(f);
            }
            context.SaveChanges();
        }
Exemple #2
0
        public static void Initializer(ForumContext context)
        {
            context.Database.EnsureCreated();

            //Look for any Users.
            if (context.Users.Any())
            {
                return;   // DB has been seeded
            }

            // var result = roleManager.CreateAsync(new IdentityRole("Admin")).Result;

            AppUser shawnaStaff = new AppUser
            {
                UserName = "******",
                Name     = "Shawna Staff"
            };

            context.Users.Add(shawnaStaff);
            context.SaveChanges();

            AppUser ivyStaff = new AppUser
            {
                UserName = "******",
                Name     = "Ivy Staff"
            };

            context.Users.Add(ivyStaff);
            context.SaveChanges();

            AppUser mikhailGuidesse = new AppUser
            {
                UserName = "******",
                Name     = "Mikhail Guidesse"
            };

            context.Users.Add(mikhailGuidesse);
            context.SaveChanges();

            ForumPosts Lighting = new ForumPosts
            {
                PostTopic  = "Lighting",
                PostText   = "The idea about using a lace curtain to defuse natural lighting is genius!",
                Name       = shawnaStaff,
                Date       = DateTime.Parse("2020-11-10"),
                PostRating = 5,
            };

            context.ForumPosts.Add(Lighting);
            context.SaveChanges();

            ForumPosts Reframing = new ForumPosts
            {
                PostTopic  = "Reframing",
                PostText   = "I didn't understand reframing.",
                Name       = ivyStaff,
                Date       = DateTime.Parse("2020-7-16"),
                PostRating = 1
            };

            context.ForumPosts.Add(Reframing);
            context.SaveChanges();

            ForumPosts GoldenHour = new ForumPosts
            {
                PostTopic  = "Golden Hour",
                PostText   = "This definitely gives me a reason to be up early.",
                Name       = mikhailGuidesse,
                Date       = DateTime.Parse("2021-1-3"),
                PostRating = 4
            };

            context.ForumPosts.Add(GoldenHour);
            context.SaveChanges();
        }