private void CreateRolesandUsers() { BookOpinionsContext context = new BookOpinionsContext(); var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); // In Startup iam creating first Admin Role and creating a default Admin User if (!roleManager.RoleExists("Admin")) { // first we create Admin rool var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Admin"; roleManager.Create(role); //Here we create a Admin super user who will maintain the website var user = new ApplicationUser(); user.UserName = "******"; user.Email = "*****@*****.**"; string userPWD = "A@Z200711"; var chkUser = UserManager.Create(user, userPWD); //Add default User to Role Admin if (chkUser.Succeeded) { var result1 = UserManager.AddToRole(user.Id, "Admin"); } } // creating Creating Manager role if (!roleManager.RoleExists("Manager")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Manager"; roleManager.Create(role); } // creating Creating Employee role if (!roleManager.RoleExists("Employee")) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = "Employee"; roleManager.Create(role); } }
public Service(BookOpinionsContext context) { this.context = context; }
public BaseController() { context = new BookOpinionsContext(); this.UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(this.context)); }