public ActionResult UpdateRoles(PartialRolesModel model) { var user = UserManager.FindById(model.UserID); if (user != null) { if (model.IsSupport == false && UserManager.IsInRole(user.Id, "Support")) { UserManager.RemoveFromRole(user.Id, "Support"); } if (model.IsSupport == true && UserManager.IsInRole(user.Id, "Support") == false) { UserManager.AddToRole(user.Id, "Support"); } if (model.IsAdmin == false && UserManager.IsInRole(user.Id, "Admin")) { UserManager.RemoveFromRole(user.Id, "Admin"); } if (model.IsAdmin == true && UserManager.IsInRole(user.Id, "Admin") == false) { UserManager.AddToRole(user.Id, "Admin"); } } else { return(RedirectToAction("NotFound", "Home")); } return(new EmptyResult()); }
public ActionResult GetRoles(string id) { if (!User.IsInRole("Admin")) { return(RedirectToAction("NotFound", "Home")); } // NO WORKING //PartialRolesModel model = new PartialRolesModel(); //model.roles= UserManager.GetRoles(id); //model.UserID = id; //return PartialView("_RolePanel", model); //IndexModel model = new IndexModel(); //model.partialBanModel = new PartialBanModel(); //Repos<ApplicationUser> repos = new Repos<ApplicationUser>(); //model.users = repos.ReadAll(); //model.partialRolesModel = new PartialRolesModel(); //model.partialRolesModel.roles= UserManager.GetRoles(id); //model.partialRolesModel.UserID = id; //if (UserManager.GetRoles(id).Contains("Admin")) // model.partialRolesModel.IsAdmin = true; //if (UserManager.GetRoles(id).Contains("Support")) // model.partialRolesModel.IsSupport = true; PartialRolesModel model = new PartialRolesModel(); model.roles = UserManager.GetRoles(id); model.UserID = id; if (UserManager.GetRoles(id).Contains("Admin")) { model.IsAdmin = true; } if (UserManager.GetRoles(id).Contains("Support")) { model.IsSupport = true; } return(PartialView("_RolePanel", model)); }