private void CreateLocalRoles() { ExtendedUserDbContext context = new ExtendedUserDbContext(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var userManager = new UserManager <ExtendedUser>(new UserStore <ExtendedUser>(context)); List <string> roles = new List <string>() { "admin", "manager", "employee" }; string adminuserId = ""; foreach (var rolename in roles) { if (roleManager.RoleExists(rolename)) { continue; } var role = new IdentityRole { Name = rolename }; var result = roleManager.Create(role); if (rolename == "admin") { adminuserId = role.Id; } } var rootUser = userManager.FindByEmail("*****@*****.**"); if (rootUser == null) { var user = new ExtendedUser { UserName = "******", FirstName = "Sameer", LastName = "Tariq", Email = "*****@*****.**", Role = adminuserId }; string pass = "******"; var chkUser = userManager.Create(user, pass); if (chkUser.Succeeded) { var result1 = userManager.AddToRole(user.Id, "admin"); } } }
public CustomAuthorize(string claim) { this.claims = claim; this.context = new ExtendedUserDbContext(); }