Beispiel #1
0
        private async Task ShowFlexibleHolidays(IDialogContext context, IAwaitable <object> result)
        {
            try
            {
                List <Holiday> flexibleHolidays = _holidayService.GetHolidays(true, _dateRange);

                await context.PostAsync($"There are a total of {flexibleHolidays.Count} Flexible holidays");

                await context.PostAsync("To Opt In any Flexible holiday, Press the Opt In button");

                var resultMessage = context.MakeMessage();
                resultMessage.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                resultMessage.Attachments      = new List <Attachment>();

                resultMessage.Attachments = HeroCardManager.CreateFlexibleHolidayCards(flexibleHolidays).ToList();


                await context.PostAsync(resultMessage);

                await context.PostAsync("If you want to leave this panel, enter quit");

                context.Wait(OptInRequest);
            }
            catch (FormCanceledException ex)
            {
                string reply;
                if (ex.InnerException == null)
                {
                    reply = "You have canceled the operation. Quitting from the Flights Search";
                }
                else
                {
                    reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}";
                }

                await context.PostAsync(reply);
            }
        }
Beispiel #2
0
        public async Task UserSelectedFlexibleHoliday(IDialogContext context, LuisResult result)
        {
            context.UserData.TryGetValue <HeroCardManager>("heroCardManager", out heroCardManager);
            context.UserData.TryGetValue <Dictionary <DateTime?, string> >("appliedOptionalHolidays", out appliedOptionalHolidays);
            context.UserData.TryGetValue <bool>("leaveAlreadySelectedFromCurrentCard", out leaveAlreadySelectedFromCurrentCard);

            if (heroCardManager == null)
            {
                heroCardManager = new HeroCardManager();
            }
            if (appliedOptionalHolidays == null)
            {
                appliedOptionalHolidays = new Dictionary <DateTime?, string>();
            }
            EntityRecommendation Selected_Optional_Holiday, Hero_Card_Id;
            DateTime             selectedOptionalHoliday = new DateTime();
            int heroCardId = 0;

            if (result.TryFindEntity("HeroCardId", out Hero_Card_Id))
            {
                Hero_Card_Id.Type = "Hero_Card_Id";
            }

            if (result.TryFindEntity("builtin.datetimeV2.datetime", out Selected_Optional_Holiday))
            {
                Selected_Optional_Holiday.Type = "Selected_Optional_Holiday";
            }

            if (Selected_Optional_Holiday != null && Selected_Optional_Holiday.Type == "Selected_Optional_Holiday")
            {
                var resolutionValues = (IList <object>)Selected_Optional_Holiday.Resolution["values"];
                selectedOptionalHoliday = Convert.ToDateTime(((IDictionary <string, object>)resolutionValues.Last())["value"]);
            }

            if (Hero_Card_Id != null && Hero_Card_Id.Type == "Hero_Card_Id")
            {
                heroCardId = Convert.ToInt32(Hero_Card_Id.Entity);
            }

            if (heroCardId == heroCardManager.currentHeroCardId && !leaveAlreadySelectedFromCurrentCard)
            {
                if (!appliedOptionalHolidays.ContainsKey(selectedOptionalHoliday))
                {
                    if (appliedOptionalHolidays.Count < 2)
                    {
                        if (selectedOptionalHoliday >= DateTime.Today)
                        {
                            appliedOptionalHolidays.Add(selectedOptionalHoliday, nagarroFlexibleHolidays[selectedOptionalHoliday]);
                            await context.PostAsync("You have successfully applied flexible holiday for : " + nagarroFlexibleHolidays[selectedOptionalHoliday] + "(" + selectedOptionalHoliday.ToString("d") + ")");

                            leaveAlreadySelectedFromCurrentCard = true;
                        }
                        else
                        {
                            await context.PostAsync("You cannot apply flexible holiday for past date. Please opt for flexible holiday from future date.");
                        }
                    }
                    else
                    {
                        await context.PostAsync("You have availed maximum of 2 flexible holidays. You cannot avail anymore holidays.");
                    }
                }
                else
                {
                    await context.PostAsync("You have already selected this flexible holiday.Please select a different holiday.");
                }
            }
            else
            {
                await context.PostAsync("You have already selected an flexible holiday from this card. Please request new options to avail another holiday.");
            }
            context.UserData.SetValue <HeroCardManager>("heroCardManager", heroCardManager);
            context.UserData.SetValue <Dictionary <DateTime?, string> >("appliedOptionalHolidays", appliedOptionalHolidays);
            context.UserData.SetValue <bool>("leaveAlreadySelectedFromCurrentCard", leaveAlreadySelectedFromCurrentCard);
        }