コード例 #1
0
        private async Task ShowHolidays(IDialogContext context, IAwaitable <object> result)
        {
            try
            {
                List <Holiday> holidays = _holidayService.GetHolidays(false, _dateRange);

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

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

                resultMessage.Attachments = AdaptiveCardJsonManager.CreateCards(holidays).ToList();

                await context.PostAsync(resultMessage);
            }
            catch (FormCanceledException ex)
            {
                string reply;
                if (ex.InnerException == null)
                {
                    reply = "You have canceled the operation.";
                }
                else
                {
                    reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}";
                }

                await context.PostAsync(reply);
            }
            finally
            {
                context.Done <object>(null);
            }
        }
コード例 #2
0
        private async Task ShowSubmittedRequests(IDialogContext context, IAwaitable <object> result)
        {
            try
            {
                var username = UserService.GetUsername(context);
                switch (_showRequest)
                {
                case ShowRequest.Flexible:
                {
                    var flexibleHolidays = await flexibleHolidayService.GetOptedInHolidays(username, _dateRange);

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

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

                    resultMessage.Attachments = AdaptiveCardJsonManager.CreateCards(flexibleHolidays).ToList();

                    if (resultMessage.Attachments.Any())
                    {
                        await context.PostAsync(resultMessage);
                    }
                    break;
                }

                case ShowRequest.Leave:
                {
                    var leaves = await leaveService.GetLeaveAsync(username, _dateRange);

                    await context.PostAsync($"There are a total of {leaves.Count} Leaves");

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

                    resultMessage.Attachments = AdaptiveCardJsonManager.CreateCards(leaves).ToList();

                    if (resultMessage.Attachments.Any())
                    {
                        await context.PostAsync(resultMessage);
                    }
                    break;
                }

                case ShowRequest.All:
                {
                    var flexibleHolidays = await flexibleHolidayService.GetOptedInHolidays(username, _dateRange);

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

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

                    resultFlexibleHolidayMessage.Attachments = AdaptiveCardJsonManager.CreateCards(flexibleHolidays).ToList();

                    if (resultFlexibleHolidayMessage.Attachments.Any())
                    {
                        await context.PostAsync(resultFlexibleHolidayMessage);
                    }
                    await context.PostAsync(resultFlexibleHolidayMessage);


                    var leaves = await leaveService.GetLeaveAsync(username, _dateRange);

                    await context.PostAsync($"There are a total of {leaves.Count} Leaves");

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

                    resultMessage.Attachments = AdaptiveCardJsonManager.CreateCards(leaves).ToList();

                    if (resultMessage.Attachments.Any())
                    {
                        await context.PostAsync(resultMessage);
                    }

                    break;
                }
                }
            }
            catch (Exception ex)
            {
                string reply;
                if (ex.InnerException == null)
                {
                    reply = "There was some error. Please try again later";
                }
                else
                {
                    reply = $"Oops! Something went wrong :( Technical Details: {ex.InnerException.Message}";
                }

                await context.PostAsync(reply);
            }
            finally
            {
                context.Done <object>(null);
            }
        }