public static async Task <IdentityResult> DeleteAccountAsync(this FaToolUserManager um, FaToolUser user) { if (user.IsAdminUser()) { return(IdentityResult.Failed("Can't delete admin user account.")); } var currentRoles = await um.GetRolesAsync(user.Id); var result = await um.RemoveFromRolesAsync(user.Id, currentRoles.ToArray()); if (result.Succeeded) { result = await um.DeleteAsync(user); } return(result); }
public static async Task <IdentityResult> LockAccountAsync(this FaToolUserManager um, FaToolUser user, int?forMinutes) { if (user.IsAdminUser()) { return(IdentityResult.Failed("Can't lock admin user account.")); } var result = await um.SetLockoutEnabledAsync(user.Id, true); if (result.Succeeded) { if (forMinutes.HasValue) { result = await um.SetLockoutEndDateAsync(user.Id, DateTimeOffset.UtcNow.AddMinutes(forMinutes.Value)); } else { result = await um.SetLockoutEndDateAsync(user.Id, DateTimeOffset.MaxValue); } } return(result); }