public async Task <TokenUser> Get(string id) { if (String.IsNullOrWhiteSpace(id)) { throw new ArgumentNullException("id"); } TokenUser tokenUser = await _tokenUserRepository.Load(id); // If TTL has passed then force delete the TokenUser and return null if (tokenUser != null && tokenUser.TTL != null) { double secondsRemaining = tokenUser.TTLSecondsRemaining(); bool isExpired = secondsRemaining <= 0; if (isExpired) { _logger.LogInformation("Deleting expired User. User Id: {0}, TTL Seconds Remaining: {1}.", tokenUser.Id, secondsRemaining); await _tokenUserRepository.Delete(id); tokenUser = null; } } return(tokenUser); }
public static string TTLPhrase(this TokenUser tokenUser) { double secondsLeft = tokenUser.TTLSecondsRemaining(); double minutesLeft = Math.Ceiling(secondsLeft / 60); if (secondsLeft > 60) { return(string.Format("for {0} more minutes", minutesLeft)); } else if (secondsLeft == 60) { return(string.Format("for {0} more minute", minutesLeft)); } else if (secondsLeft < 60 && secondsLeft > 0) { if (secondsLeft == 1) { return(string.Format("for {0} more second", secondsLeft)); } return(string.Format("for {0} more seconds", secondsLeft)); } return("momentarily"); }