Esempio n. 1
0
        public static void InitializeUsersRolesDb(UsersRolesDB context)
        {
            context.Database.EnsureCreated();

            if (!context.UserRoles.Any())
            {
                SeedUsersRolesDB.GenerateSeed(context);
            }

            context.SaveChanges();
        }
Esempio n. 2
0
        public static void GenerateSeed(UsersRolesDB context)
        {
            context.Roles.Add(new IdentityRole {
                Id = "1", Name = RoleConst.ADMIN, NormalizedName = RoleConst.ADMIN.ToUpper()
            });
            context.Roles.Add(new IdentityRole {
                Id = "2", Name = RoleConst.PROFESSOR, NormalizedName = RoleConst.PROFESSOR.ToUpper()
            });
            context.Roles.Add(new IdentityRole {
                Id = "3", Name = RoleConst.STUDENT, NormalizedName = RoleConst.STUDENT.ToUpper()
            });

            context.Users.Add(new IdentityUser
            {
                Id                 = "1",
                UserName           = "******",
                Email              = "*****@*****.**",
                PasswordHash       = "AQAAAAEAACcQAAAAEASy7osooMIdwVsTCMuoc0ZDcz/PSggn0qr1okXMA1RI0/7y8wH/zb1vihChb83/+A==",
                EmailConfirmed     = true,
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******"
            });
            context.Users.Add(new IdentityUser
            {
                Id                 = "2",
                UserName           = "******",
                Email              = "*****@*****.**",
                PasswordHash       = "AQAAAAEAACcQAAAAEASy7osooMIdwVsTCMuoc0ZDcz/PSggn0qr1okXMA1RI0/7y8wH/zb1vihChb83/+A==",
                EmailConfirmed     = true,
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******"
            });
            context.Users.Add(new IdentityUser
            {
                Id                 = "3",
                UserName           = "******",
                Email              = "*****@*****.**",
                PasswordHash       = "AQAAAAEAACcQAAAAEASy7osooMIdwVsTCMuoc0ZDcz/PSggn0qr1okXMA1RI0/7y8wH/zb1vihChb83/+A==",
                EmailConfirmed     = true,
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******"
            });
            context.Users.Add(new IdentityUser
            {
                Id                 = "4",
                UserName           = "******",
                Email              = "*****@*****.**",
                PasswordHash       = "AQAAAAEAACcQAAAAEASy7osooMIdwVsTCMuoc0ZDcz/PSggn0qr1okXMA1RI0/7y8wH/zb1vihChb83/+A==",
                EmailConfirmed     = true,
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******"
            });
            context.Users.Add(new IdentityUser
            {
                Id                 = "5",
                UserName           = "******",
                Email              = "*****@*****.**",
                PasswordHash       = "AQAAAAEAACcQAAAAEASy7osooMIdwVsTCMuoc0ZDcz/PSggn0qr1okXMA1RI0/7y8wH/zb1vihChb83/+A==",
                EmailConfirmed     = true,
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******"
            });
            context.Users.Add(new IdentityUser
            {
                Id                 = "6",
                UserName           = "******",
                Email              = "*****@*****.**",
                PasswordHash       = "AQAAAAEAACcQAAAAEASy7osooMIdwVsTCMuoc0ZDcz/PSggn0qr1okXMA1RI0/7y8wH/zb1vihChb83/+A==",
                EmailConfirmed     = true,
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******"
            });
            context.Users.Add(new IdentityUser
            {
                Id                 = "7",
                UserName           = "******",
                Email              = "*****@*****.**",
                PasswordHash       = "AQAAAAEAACcQAAAAEASy7osooMIdwVsTCMuoc0ZDcz/PSggn0qr1okXMA1RI0/7y8wH/zb1vihChb83/+A==",
                EmailConfirmed     = true,
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******"
            });
            context.Users.Add(new IdentityUser
            {
                Id                 = "8",
                UserName           = "******",
                Email              = "*****@*****.**",
                PasswordHash       = "AQAAAAEAACcQAAAAEASy7osooMIdwVsTCMuoc0ZDcz/PSggn0qr1okXMA1RI0/7y8wH/zb1vihChb83/+A==",
                EmailConfirmed     = true,
                NormalizedEmail    = "*****@*****.**",
                NormalizedUserName = "******"
            });

            context.UserRoles.Add(new IdentityUserRole <string> {
                UserId = "1", RoleId = "1"
            });
            context.UserRoles.Add(new IdentityUserRole <string> {
                UserId = "2", RoleId = "2"
            });
            context.UserRoles.Add(new IdentityUserRole <string> {
                UserId = "3", RoleId = "2"
            });
            context.UserRoles.Add(new IdentityUserRole <string> {
                UserId = "4", RoleId = "3"
            });
            context.UserRoles.Add(new IdentityUserRole <string> {
                UserId = "5", RoleId = "3"
            });
            context.UserRoles.Add(new IdentityUserRole <string> {
                UserId = "6", RoleId = "3"
            });
            context.UserRoles.Add(new IdentityUserRole <string> {
                UserId = "7", RoleId = "3"
            });
            context.UserRoles.Add(new IdentityUserRole <string> {
                UserId = "8", RoleId = "3"
            });

            context.SaveChanges();
        }