/// <summary> /// Resumes after appointments dialog is completed /// </summary> /// <param name="context">The context object</param> /// <param name="result">Return Task object</param> /// <returns>Returns Task</returns> private async Task ResumeAfterAppointmentsFormDialog(IDialogContext context, IAwaitable <AppointmentsQuery> result) { try { var searchQuery = await result; var appointments = await this.GetAppointmentsAsync(searchQuery); var appointmentsQueryFormDialog = FormDialog.FromForm( this.BuildAppointmentsForm, FormOptions.PromptInStart); if (appointments.Count() == 0) { var nextAppointment = PortalHelper.GetNextAvailableAppointment(searchQuery.Date.AddDays(1)); if (nextAppointment != null) { this.dynamicPromptOption1 = nextAppointment.Date.ToShortDateString() + " " + nextAppointment.Date.ToShortTimeString(); this.dynamicPromptOption2 = "Some other date"; PromptDialog.Choice(context, this.ResumeAfterNextAppointment, new List <string>() { this.dynamicPromptOption1, this.dynamicPromptOption2 }, $"Oops! No appointment available on {searchQuery.Date.ToShortDateString()}.", "Sorry! I didn't get that. Try typing one of options listed above", 5); } else { await context.PostAsync("Please type another date."); context.Call(appointmentsQueryFormDialog, this.ResumeAfterAppointmentsFormDialog); } } else { // await context.PostAsync($"I found in total {Appointments.Count()} appoitments for your dates:"); var appDlg = new AppointmentsListDialog(); appDlg.Appointments = appointments.ToList(); context.Call(appDlg, this.ResumeAfterOptionDialog); } } catch (FormCanceledException ex) { string reply; if (ex.InnerException == null) { reply = "You have canceled the operation. Quitting from the AppointmentsDialog"; } else { reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}"; } await context.PostAsync(reply); } }
/// <summary> /// Returns Next available appointment /// </summary> /// <param name="context">Dialog context object</param> /// <param name="result"> Query Date string </param> /// <returns>returns next appointment</returns> private async Task ResumeAfterNextAppointment(IDialogContext context, IAwaitable <string> result) { string optionSelected = await result; if (optionSelected == this.dynamicPromptOption1) { var confirmedAppointment = Convert.ToDateTime(optionSelected); await context.PostAsync($"Great! You chose to book appointment on {confirmedAppointment.ToShortDateString()} at {confirmedAppointment.ToShortTimeString()}"); var appointListDialog = new AppointmentsListDialog(); appointListDialog.ShowConfirmationOptions(context); } else if (optionSelected == this.dynamicPromptOption2) { var appointmentsFormDialog = FormDialog.FromForm(this.BuildAppointmentsForm, FormOptions.PromptInStart); context.Call(appointmentsFormDialog, this.ResumeAfterAppointmentsFormDialog); } }