private void createRolesandUsers() { ApplicationDbContext1 context = new ApplicationDbContext1(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var UserManager = new UserManager <ApplicationUser1>(new UserStore <ApplicationUser1>(context)); // In Startup iam creating first Admin Role and creating a default Admin User if (!roleManager.RoleExists("Admin")) { // first we create Admin role var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Admin"; roleManager.Create(role); } var user = new ApplicationUser1(); user.UserName = "******"; user.Email = "*****@*****.**"; string userPassword = "******"; var checkUser = UserManager.Create(user, userPassword); if (checkUser.Succeeded) { var result1 = UserManager.AddToRole(user.Id, "Admin"); } // creating Creating TrainingStaff role if (!roleManager.RoleExists("Staff")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Staff"; roleManager.Create(role); } // creating Creating Trainer role if (!roleManager.RoleExists("Trainer")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Trainer"; roleManager.Create(role); } // creating Creating Trainee role if (!roleManager.RoleExists("Trainee")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Trainee"; roleManager.Create(role); } }
public Boolean isAdminUser() { if (User.Identity.IsAuthenticated) { var user = User.Identity; ApplicationDbContext1 context = new ApplicationDbContext1(); var UserManager = new UserManager <ApplicationUser1>(new UserStore <ApplicationUser1>(context)); var s = UserManager.GetRoles(user.GetUserId()); if (s[0].ToString() == "Admin") { return(true); } else { return(false); } } return(false); }
public TrainerTopicsController() { _context = new ApplicationDbContext1(); }
public AccountController() { context = new ApplicationDbContext1(); }
public RolesController() { context = new ApplicationDbContext1(); }
public TraineeCoursesController() { _context = new ApplicationDbContext1(); }
public ManageUsersController() { _context = new ApplicationDbContext1(); }
public ManagerStaffViewModelsController() { _context = new ApplicationDbContext1(); }