/// <summary> /// Adds or removes a role for a user account. /// </summary> /// <param name="username">The user which roles should be modified.</param> /// <param name="rolename">The role which should be added or removed.</param> /// <param name="isInRole">The new role status for the user account. If false, the role will be deleted for the user account.</param> /// <returns></returns> public JsonResult AddRemoveRoleForUser(string userId, string rolename, bool isInRole) { MyJsonResult result; IdentityResult res = _userAccountService.AddRemoveRoleForUser(userId, rolename, isInRole); if (res.Succeeded) { var action = isInRole ? "added" : "removed"; var msg = string.Format("The role {0} has been {1} for user {2}.", rolename, action, userId); result = MyJsonResult.CreateSuccess(msg); } else { ModelState.AddModelError("", res.Errors.First()); result = MyJsonResult.CreateError("Could not remove role for user: " + res.Errors); } return(Json(result)); }