public async Task<ActionResult> EditRole(EditRole model) { if (!Request.IsAjaxRequest()) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } if (!ModelState.IsValid) { return Json(new { success = false, type = 1, message = "Error! Model state is not valid." }, JsonRequestBehavior.AllowGet); } var role = await RoleManager.FindByIdAsync(model.Id); role.Name = model.Name; var updateRole = await RoleManager.UpdateAsync(role); { return !updateRole.Succeeded ? Json(new { success = false, type = 1, message = "Error! Role cannot be null." }, JsonRequestBehavior.AllowGet) : Json(new { success = true, type = 3, message = "Role updated!" }, JsonRequestBehavior.AllowGet); } }
public async Task<ActionResult> EditRole(string id) { if (!Request.IsAjaxRequest()) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var role = await RoleManager.FindByIdAsync(id); if (id == null || role == null) { return Json(new { success = false, type = 1, message = "Error! Role cannot be null." }, JsonRequestBehavior.AllowGet); } var users = new List<User>(); foreach (var user in UserManager.Users.ToList()) { if (await UserManager.IsInRoleAsync(user.Id, role.Name)) { users.Add(user); } } ViewBag.Users = users; var model = new EditRole { Id = role.Id, Name = role.Name }; return PartialView("_EditRole", model); }