Ejemplo n.º 1
0
        protected async override void Seed(TARDBContext context)
        {
            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Admin"
                };

                manager.Create(role);
            }
            if (!context.Roles.Any(r => r.Name == "Staff"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Staff"
                };

                manager.Create(role);
            }
            if (!context.Roles.Any(r => r.Name == "Member"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Member"
                };

                manager.Create(role);
            }
            if (!context.Users.Any(r => r.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <TARUser>(context);
                var manager = new UserManager <TARUser>(store);
                var user    = new TARUser {
                    UserName = "******", Email = "*****@*****.**", DisplayName = "Admin", ImagePath = "~/Content/Images/Empty_pic.png"
                };
                var result = manager.Create(user, "Admin@123");
            }
            if (!context.Users.Any(r => r.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <TARUser>(context);
                var manager = new UserManager <TARUser>(store);
                var user    = new TARUser {
                    UserName = "******", Email = "*****@*****.**", DisplayName = "Staff", ImagePath = "~/Content/Images/Empty_pic.png"
                };
                var result = manager.Create(user, "Staff@123");
            }
            if (!context.Users.Any(r => r.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <TARUser>(context);
                var manager = new UserManager <TARUser>(store);
                var user    = new TARUser {
                    UserName = "******", Email = "*****@*****.**", DisplayName = "Member", ImagePath = "~/Content/Images/Empty_pic.png"
                };
                var result = manager.Create(user, "Member@123");
            }


            context.SaveChanges();

            if (context.Users.Any(r => r.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <TARUser>(context);
                var manager = new UserManager <TARUser>(store);
                var user    = context.Users.FirstOrDefault(r => r.UserName == "*****@*****.**");
                var role    = context.Roles.FirstOrDefault(r => r.Name == "Admin");
                user.Roles.Add(new IdentityUserRole()
                {
                    UserId = user.Id, RoleId = role.Id
                });
            }
            if (context.Users.Any(r => r.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <TARUser>(context);
                var manager = new UserManager <TARUser>(store);
                var user    = context.Users.FirstOrDefault(r => r.UserName == "*****@*****.**");
                var role    = context.Roles.FirstOrDefault(r => r.Name == "Staff");
                user.Roles.Add(new IdentityUserRole()
                {
                    UserId = user.Id, RoleId = role.Id
                });
            }
            if (context.Users.Any(r => r.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <TARUser>(context);
                var manager = new UserManager <TARUser>(store);
                var user    = context.Users.FirstOrDefault(r => r.UserName == "*****@*****.**");
                var role    = context.Roles.FirstOrDefault(r => r.Name == "Member");
                user.Roles.Add(new IdentityUserRole()
                {
                    UserId = user.Id, RoleId = role.Id
                });
            }
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        protected async override void Seed(TARDBContext context)
        {
            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Admin"
                };

                manager.Create(role);
            }
            if (!context.Roles.Any(r => r.Name == "Staff"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Staff"
                };

                manager.Create(role);
            }
            if (!context.Roles.Any(r => r.Name == "Member"))
            {
                var store   = new RoleStore <IdentityRole>(context);
                var manager = new RoleManager <IdentityRole>(store);
                var role    = new IdentityRole {
                    Name = "Member"
                };

                manager.Create(role);
            }
            if (!context.Users.Any(r => r.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <TARUser>(context);
                var manager = new UserManager <TARUser>(store);
                var user    = new TARUser {
                    UserName = "******", Email = "*****@*****.**"
                };
                var result = await manager.CreateAsync(user, "Admin@123");

                if (result.Succeeded)
                {
                    await store.AddToRoleAsync(user, "Admin");
                }
            }
            if (!context.Users.Any(r => r.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <TARUser>(context);
                var manager = new UserManager <TARUser>(store);
                var user    = new TARUser {
                    UserName = "******", Email = "*****@*****.**"
                };
                var result = await manager.CreateAsync(user, "Staff@123");

                if (result.Succeeded)
                {
                    await store.AddToRoleAsync(user, "Staff");
                }
            }
            if (!context.Users.Any(r => r.UserName == "*****@*****.**"))
            {
                var store   = new UserStore <TARUser>(context);
                var manager = new UserManager <TARUser>(store);
                var user    = new TARUser {
                    UserName = "******", Email = "*****@*****.**"
                };
                var result = await manager.CreateAsync(user, "Member@123");

                if (result.Succeeded)
                {
                    await store.AddToRoleAsync(user, "Member");
                }
            }

            context.SaveChanges();
        }