public ActionResult ManageRole() { ApplicationDbContext context = new ApplicationDbContext(); var roles = context.Roles.Select(r => new SelectListItem { Value = r.Id, Text = r.Name }); var users = context.Users.Select(u => new SelectListItem { Value = u.Id, Text = u.UserName }); ManageRoleViewModel manageRoleViewModel = new ManageRoleViewModel() { RoleList = roles, UserList = users }; return(View(manageRoleViewModel)); }
public ActionResult ManageRole2(ManageRoleViewModel model) { #region Adding Roles to database //ApplicationDbContext context = new ApplicationDbContext(); //string[] roles = { "Acting Department Head", "Department Representative", "Department Head", "Store Clerk", "Store Supervisor", "Store Manager" }; //foreach (var role in roles) //{ // context.Roles.Add(new IdentityRole() { Name = role }); //} //context.SaveChanges(); #endregion #region Assign users to role using DDL //string roleId = model.RoleId; //string userId = model.UserId; //ApplicationDbContext context = new ApplicationDbContext(); //var role = context.Roles.FirstOrDefault(x => x.Id == roleId).Name; //ApplicationUserManager manager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); //manager.AddToRole(userId, role); return(RedirectToAction("Index", "Home")); #endregion }