private async Task SearchFormComplete(IDialogContext context, IAwaitable <SessionSelectionOptions> result)
 {
     try
     {
         var state = await result;
         await SessionSelectionOptions.SearchSessionsAndPostResults(context, state);
     }
     catch (FormCanceledException <SessionSelectionOptions> )
     {
         await context.PostAsync("Sorry I couldn't help you with that one. Care to try again? I'll try to do better this time.");
     }
     context.Wait(MessageReceived);
 }
        public async Task FindSession(IDialogContext context, LuisResult result)
        {
            var entity = result.Entities.FirstOrDefault();

            if (entity != null)
            {
                switch (entity.Type)
                {
                case "Speaker":
                    var speakerName = entity.Entity;
                    var speakers    = CodeCamp.FindSpeakers(speakerName);
                    switch (speakers.Count())
                    {
                    case 0:
                        await context.PostAsync($"Sorry, I can't find any speakers named {speakerName}.");

                        context.Wait(MessageReceived);
                        break;

                    case 1:
                        await SessionSelectionOptions.SearchSessionsAndPostResults(
                            context, new SessionSelectionOptions()
                        {
                            SpeakerName = speakerName
                        });

                        context.Wait(MessageReceived);
                        break;

                    default:
                        await context.PostAsync($"I've found {speakers.Count()} speakers named {speakerName}.");

                        var options1 = new SessionSelectionOptions()
                        {
                            CandidateSpeakers = speakers.ToArray()
                        };
                        var sessionDialog1 = new FormDialog <SessionSelectionOptions>(
                            options1,
                            SessionSelectionOptions.BuildFormForSpeakerDisambiguation,
                            FormOptions.PromptInStart
                            );

                        context.Call(sessionDialog1, SearchFormComplete);

                        break;
                    }

                    break;

                case "Topic":
                    var topic   = entity.Entity;
                    var options = new SessionSelectionOptions()
                    {
                        Topic = topic
                    };
                    var sessionDialog = new FormDialog <SessionSelectionOptions>(
                        options,
                        SessionSelectionOptions.BuildFormForGeneralSearch,
                        FormOptions.PromptInStart
                        );

                    context.Call(sessionDialog, SearchFormComplete);

                    break;

                case "Company":
                    var company = entity.Entity;

                    await SessionSelectionOptions.SearchSessionsAndPostResults(
                        context, new SessionSelectionOptions()
                    {
                        CompanyName = company
                    });

                    context.Wait(MessageReceived);

                    break;

                default:
                    await context.PostAsync("Sorry, I can't understand what type of session you're looking for.");

                    context.Wait(MessageReceived);
                    break;
                }
            }
            else
            {
                // general session search
                var options       = new SessionSelectionOptions();
                var sessionDialog = new FormDialog <SessionSelectionOptions>(
                    options,
                    SessionSelectionOptions.BuildFormForGeneralSearch,
                    FormOptions.PromptInStart
                    );

                context.Call(sessionDialog, SearchFormComplete);
            }
        }