Exemplo n.º 1
0
        private void CreateUser(SmileTechDbContext context)
        {
            var manager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new SmileTechDbContext()));

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new SmileTechDbContext()));

            var user = new ApplicationUser()
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                BirthDay       = DateTime.Now,
                FullName       = "Smile Tech"
            };

            manager.Create(user, "123654$");

            if (!roleManager.Roles.Any())
            {
                roleManager.Create(new IdentityRole {
                    Name = "Admin"
                });
                roleManager.Create(new IdentityRole {
                    Name = "User"
                });
            }

            var adminUser = manager.FindByEmail("*****@*****.**");

            manager.AddToRoles(adminUser.Id, new string[] { "Admin", "User" });
        }
Exemplo n.º 2
0
 public SmileTechDbContext Init()
 {
     return(dbContext ?? (dbContext = new SmileTechDbContext()));
 }