protected override void Seed(Nsu.Belov.TrainsDatabase.Database.TrainsDataContext context) { UserStore<ApplicationUser> userStore = new UserStore<ApplicationUser>(context); RoleStore<IdentityRole> roleStore = new RoleStore<IdentityRole>(context); TrainsUserManager userManager = new TrainsUserManager(userStore); TrainsRoleManager roleManager = new TrainsRoleManager(roleStore); IdentityRole adminRole = context.Roles.FirstOrDefault(x => x.Name == "admin"); if (adminRole == null) { roleManager.Create(new IdentityRole("admin")); } IdentityRole operatorRole = context.Roles.FirstOrDefault(x => x.Name == "operator"); if (operatorRole == null) { roleManager.Create(new IdentityRole("operator")); } ApplicationUser admin = context.Users.FirstOrDefault(u => u.UserName == "admin"); if (admin == null) { admin = new ApplicationUser() { UserName = "******" }; userManager.Create(admin, "admin1"); //незнаю можно ли не сохраная контекст достать еще раз через него admin = userManager.FindByName("admin"); } userManager.AddToRole(admin.Id, "admin"); userManager.AddToRole(admin.Id, "operator"); }
public AuthController(TrainsUserManager userManager, TrainsSignInManager signIn, IAuthenticationManager authentication, TrainsRoleManager roleManager) { _userManager = userManager; _signIn = signIn; _authentication = authentication; _roleManager = roleManager; }