Exemple #1
0
        private async Task <DialogTurnResult> CinemaStepAsync(WaterfallStepContext stepContext,
                                                              CancellationToken cancellationToken)
        {
            var bookingDetails = (BookingDetails)stepContext.Options;

            bookingDetails.MovieDate = (string)stepContext.Result;
            var movieName = bookingDetails.Movie.Name;

            var localizedMovieDate = getLocalizedDate(bookingDetails.MovieDate);
            var showList           = cinemaService.GetMovieShowList(movieName.ToLower(), bookingDetails.MovieDate);

            await needToTranslateProperty.SetAsync(stepContext.Context, false, cancellationToken);

            if (bookingDetails.Show != null)
            {
                var cinemaName = bookingDetails.Show.Cinema.Name;
                cinemaName          = cinemaService.GetRealCinemaName(cinemaName);
                bookingDetails.Show = showList.FirstOrDefault(show => show.Cinema.Name == cinemaName);
                if (bookingDetails.Show == null)
                {
                    var notGoing = await TranslateIfNeedAsync("does not go");

                    var inCinema = await TranslateIfNeedAsync("in");

                    await stepContext.Context.SendActivityAsync(MessageFactory.Text($"\"{movieName}\" {notGoing} " +
                                                                                    $"{localizedMovieDate} {inCinema} {cinemaName}"), cancellationToken);
                }
            }

            if (bookingDetails.Show == null)
            {
                var searching = await TranslateIfNeedAsync("Searching for cinemas where");

                var isGoing = await TranslateIfNeedAsync("is going");

                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"{searching} " +
                                                                                $"\"{movieName}\" {isGoing} {localizedMovieDate}..."), cancellationToken);

                var reply = stepContext.Context.Activity.CreateReply();
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;

                await needToTranslateProperty.SetAsync(stepContext.Context, true, cancellationToken);

                await stepContext.Context.SendActivityAsync(MessageFactory.Text(
                                                                $"I found in total {showList.Count()} movie screenings on {localizedMovieDate}:"), cancellationToken);

                foreach (var show in showList)
                {
                    var cinema    = show.Cinema;
                    var startTime = show.StartTime.ToString("HH:mm");
                    var endTime   = show.EndTime.ToString("HH:mm");
                    var heroCard  = new HeroCard()
                    {
                        Title    = cinema.Name,
                        Subtitle = cinema.Address,
                        Text     = await TranslateIfNeedAsync($"Show time: {startTime} - {endTime}"),
                        Buttons  = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title = await TranslateIfNeedAsync("More details"),
                                Type  = ActionTypes.OpenUrl,
                                Value = $"https://www.bing.com/search?q={cinema.Name}"
                            }
                        },
                        Tap = new CardAction()
                        {
                            Title = "",
                            Type  = ActionTypes.ImBack,
                            Value = $"{cinema.Name}, {startTime} - {endTime}"
                        }
                    };
                    reply.Attachments.Add(heroCard.ToAttachment());
                }
                await needToTranslateProperty.SetAsync(stepContext.Context, false, cancellationToken);

                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = reply }));
            }
            return(await stepContext.NextAsync(bookingDetails.Show, cancellationToken));
        }