Esempio n. 1
0
        private static void seedUsersTable(StudentPaperServiceContext context)
        {
            List <Professor>        professors        = new List <Professor>();
            List <Subject>          subjects          = new List <Subject>();
            List <ProfessorSubject> professorSubjects = new List <ProfessorSubject>();
            List <Student>          students          = new List <Student>();
            List <SeminarPaper>     seminarPapers     = new List <SeminarPaper>();

            seedData(out professors, out subjects, out professorSubjects, out students, out seminarPapers);

            Admin admin = new Admin()
            {
                Id = "11", AccessFailedCount = 0, ConcurrencyStamp = "b58d0834-4428-4b8b-8585-54f91a26ba71", Email = null, EmailConfirmed = false, LockoutEnabled = true, LockoutEnd = null, NormalizedEmail = null, NormalizedUserName = "******", PasswordHash = "AQAAAAEAACcQAAAAEHBL8bFd9GJAYlw8zQiyUsq4Qg+7/1XOo3XBQwUwx50VIlJcoqi8GgrMwGF5DzHFiw==", PhoneNumber = null, PhoneNumberConfirmed = false, SecurityStamp = "ac1d41a1-6a1b-43d5-83d0-1eb64223e354", TwoFactorEnabled = false, UserName = "******"
            };

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

            context.Users.AddRange(professors);
            context.SaveChanges();

            context.Users.AddRange(students);
            context.SaveChanges();

            context.Subjects.AddRange(subjects);
            context.SaveChanges();

            context.ProfessorSubjects.AddRange(professorSubjects);
            context.SaveChanges();

            context.SeminarPapers.AddRange(seminarPapers);
            context.SaveChanges();
        }
Esempio n. 2
0
        private static void seedUserRolesTable(StudentPaperServiceContext context)
        {
            context.UserRoles.AddRange(
                new IdentityUserRole <string>()
            {
                UserId = "11", RoleId = "1"
            },
                new IdentityUserRole <string>()
            {
                UserId = "21", RoleId = "2"
            },
                new IdentityUserRole <string>()
            {
                UserId = "22", RoleId = "2"
            },
                new IdentityUserRole <string>()
            {
                UserId = "23", RoleId = "2"
            },
                new IdentityUserRole <string>()
            {
                UserId = "24", RoleId = "2"
            },
                new IdentityUserRole <string>()
            {
                UserId = "25", RoleId = "2"
            },
                new IdentityUserRole <string>()
            {
                UserId = "31", RoleId = "3"
            },
                new IdentityUserRole <string>()
            {
                UserId = "32", RoleId = "3"
            },
                new IdentityUserRole <string>()
            {
                UserId = "33", RoleId = "3"
            },
                new IdentityUserRole <string>()
            {
                UserId = "34", RoleId = "3"
            },
                new IdentityUserRole <string>()
            {
                UserId = "35", RoleId = "3"
            },
                new IdentityUserRole <string>()
            {
                UserId = "36", RoleId = "3"
            }
                );

            context.SaveChanges();
        }
Esempio n. 3
0
        public static bool AllMigrationsApplied(this StudentPaperServiceContext context)
        {
            var applied = context.GetService <IHistoryRepository>()
                          .GetAppliedMigrations()
                          .Select(m => m.MigrationId);

            var total = context.GetService <IMigrationsAssembly>()
                        .Migrations
                        .Select(m => m.Key);

            return(!total.Except(applied).Any());
        }
Esempio n. 4
0
        public static StudentPaperServiceContext EnsureDatabaseSeeded(this StudentPaperServiceContext context)
        {
            if (!context.Roles.Any())
            {
                seedRolesTable(context);
            }

            if (!context.Users.Any())
            {
                seedUsersTable(context);
            }

            if (!context.UserRoles.Any())
            {
                seedUserRolesTable(context);
            }

            return(context);
        }
Esempio n. 5
0
        private static void seedRolesTable(StudentPaperServiceContext context)
        {
            context.Roles.AddRange(
                new IdentityRole()
            {
                Id = "1", Name = "admin"
            },
                new IdentityRole()
            {
                Id = "2", Name = "profesor"
            },
                new IdentityRole()
            {
                Id = "3", Name = "student"
            }
                );

            context.SaveChanges();
        }