public ActionResult AddUserToRole(AddRoleToUsers model) { try { var user = UserManager.FindByEmail(model.SelectedUserEmail); UserManager.RemoveFromRole(user.Id, "Administrator"); UserManager.RemoveFromRole(user.Id, "User"); UserManager.AddToRole(user.Id, model.SelectedRole); return(RedirectToAction("Index", "Home")); } catch (Exception e) { return(HttpNotFound()); } }
public ActionResult AddUserToRole() { AddRoleToUsers model = new AddRoleToUsers(); model.Roles.Add("Administrator"); model.Roles.Add("User"); ViewBag.UserName = this.User.Identity.Name; var AllUsers = UserManager.Users.ToList(); var WithoutCurrentUser = new List <ApplicationUser>(); foreach (var item in AllUsers) { if (item.UserName != this.User.Identity.Name) { WithoutCurrentUser.Add(item); } } ViewBag.Users = WithoutCurrentUser; return(View(model)); }