// GET: Role/Delete/5 public async Task <ActionResult> Delete(string username, string roleName) { DeleteUserRoleViewModel deleteuserVM = new DeleteUserRoleViewModel(); deleteuserVM.ID = FindUserIDByUsername(username); deleteuserVM.roleToDelete = roleName; if (deleteuserVM.ID != null && roleName != null) { await DeleteRolesAsync(deleteuserVM.ID, roleName); } return(RedirectToAction("Index")); }
public async Task <IActionResult> RemoveUserRoleAsync([FromBody] DeleteUserRoleViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(model.UserName); var roleResult = await _userManager.RemoveFromRoleAsync(user, model.RoleName); if (!roleResult.Succeeded) { AddErrors(roleResult); } } return(RedirectToAction("Manage", "Account")); }
public async Task <IActionResult> AddUserRoleAsync([FromBody] DeleteUserRoleViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(model.UserName); var roleResult = await _userManager.AddToRoleAsync(user, model.RoleName); if (!roleResult.Succeeded) { AddErrors(roleResult); } } //return PartialView("_UserRolesPartial",roleInputViewModel); return(RedirectToAction("Manage", "Account")); }