async Task ResumeAfterWineFormAsync(IDialogContext context, IAwaitable <WineForm> result)
        {
            WineForm wineResult = await result;

            string message = await ProcessWineResultsAsync(wineResult);

            await context.PostAsync(message);

            context.Wait(MessageReceivedAsync);
        }
 IDialog <string> DoSearchCase()
 {
     return
         (Chain
          .From(() => FormDialog.FromForm(new WineForm().BuildForm, FormOptions.PromptInStart))
          .ContinueWith(async(ctx, res) =>
     {
         WineForm wineResult = await res;
         string message = await ProcessWineResultsAsync(wineResult);
         return Chain.Return(message);
     }));
 }
        async Task <string> ProcessWineResultsAsync(WineForm wineResult)
        {
            List[] wines =
                await new WineApi().SearchAsync(
                    (int)wineResult.WineType,
                    (int)wineResult.Rating,
                    wineResult.InStock == StockingType.InStock,
                    "");

            string message;

            if (wines.Any())
            {
                message = "Here are the top matching wines: " +
                          string.Join(", ", wines.Select(w => w.Name));
            }
            else
            {
                message = "Sorry, No wines found matching your criteria.";
            }

            return(message);
        }
        async Task DoChainLoopAsync(IDialogContext context)
        {
            IDialog <WineForm> chain =
                Chain.From(() => FormDialog.FromForm(new WineForm().BuildForm, FormOptions.PromptInStart))
                .Do(async(ctx, result) =>
            {
                try
                {
                    WineForm wineResult = await result;
                    string message      = await ProcessWineResultsAsync(wineResult);
                    await ctx.PostAsync(message);
                }
                catch (FormCanceledException fce)
                {
                    await ctx.PostAsync($"Cancelled: {fce.Message}");
                }
            })
                .Loop();

            await context.Forward(
                chain,
                ResumeAfterWineFormAsync,
                context.Activity.AsMessageActivity());
        }