public async Task <IdentityResult> RemoveUserAsync(int id) { var user = await _userManager .Users.FirstOrDefaultAsync(u => u.Id == id) .ConfigureAwait(false); if (user == null) { return(IdentityResult.Failed(new IdentityError { Code = "UserNotFound", Description = "User not found!" })); } if (DefaultUsers.All().Select(u => u.UserName).Contains(user.UserName)) { return(IdentityResult.Failed(new IdentityError() { Code = "CannotRemoveSystemUser", Description = "You cannot remove system user!" })); } var removeUserResult = await _userManager.DeleteAsync(user).ConfigureAwait(false); if (!removeUserResult.Succeeded) { return(removeUserResult); } user.UserRoles.Clear(); return(removeUserResult); }
public static User[] BuildApplicationUsers() { return(DefaultUsers.All().ToArray()); }