Esempio n. 1
0
        public override async Task HandleAsync(CallbackQueryUpdateMessage message)
        {
            if (!int.TryParse(Parameter, out int currentPageNumber))
            {
                currentPageNumber = 1;
            }

            var mainMetric = _metricRepository.GetMainByExternalId(message.ChatId);

            if (mainMetric == null)
            {
                await _botClient.SendTextMessageAsync(message, MessageCode.NoMainMetric);

                return;
            }

            var valueNames = _valueRepository.GetByMetricId(mainMetric.Id, currentPageNumber, PagingMenuData.DefaultPageSize)
                             .ToDictionary(m => FormatKey(m.Id), m => $"{m}");

            var count     = _valueRepository.CountByMetric(mainMetric.Id);
            var pageCount = (count / PagingMenuData.DefaultPageSize) + 1;

            var menuData = new PagingMenuData
            {
                ButtonTexts = valueNames,
                CurrentPage = currentPageNumber,
                PageCount   = pageCount,
                Previous    = ButtonCode.Menu,
            };

            message = message with {
                MenuMessageId = MenuMessageId
            };
            await _botClient.EditTextButtonsMenuWithPagingAsync(message, Button, menuData);
        }
    }