private static async Task ArrivalTimeValidator(ITurnContext context, BotPrompts.DateTimeResult result) { if (result.Resolution.Count == 0) { await context.SendActivity("Sorry, I could not understand your preffered time."); result.Status = BotPrompts.PromptStatus.NotRecognized; } var now = DateTime.Now; DateTime time = default(DateTime); var resolution = result.Resolution.FirstOrDefault( res => DateTime.TryParse(res.Value, out time) && time > now); if (resolution != null) { result.Resolution.Clear(); result.Resolution.Add(resolution); } else { await context.SendActivity("Please time after 6 pm"); result.Status = BotPrompts.PromptStatus.OutOfRange; } }
private static async Task TimeValidator(ITurnContext context, DateTimeResult result) { if (result.Resolution.Count == 0) { await context.SendActivity("Sorry, I did not recognize the time that you entered."); result.Status = PromptStatus.NotRecognized; } // Find any recognized time that is not in the past. var now = DateTime.Now; DateTime time = default(DateTime); var resolution = result.Resolution.FirstOrDefault( res => DateTime.TryParse(res.Value, out time) && time > now); if (resolution != null) { // If found, keep only that result. result.Resolution.Clear(); result.Resolution.Add(resolution); } else { // Otherwise, flag the input as out of range. await context.SendActivity("Please enter a time in the future, such as \"tomorrow at 9am\""); result.Status = PromptStatus.OutOfRange; } }