AuthorsMenu.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Threading.Tasks;
  2. using CardCollector.Controllers;
  3. using CardCollector.DataBase.Entity;
  4. using CardCollector.DataBase.EntityDao;
  5. using CardCollector.Resources;
  6. using Telegram.Bot.Types;
  7. namespace CardCollector.Commands.CallbackQuery
  8. {
  9. /* Реализует нажатие на кнопку "Автор" (открывается меню с выбором автора) */
  10. public class AuthorsMenu : CallbackQueryCommand
  11. {
  12. protected override string CommandText => Command.authors_menu;
  13. protected override bool ClearMenu => false;
  14. protected override bool AddToStack => true;
  15. public override async Task Execute()
  16. {
  17. var page = int.Parse(CallbackData.Split('=')[1]);
  18. /* Получаем из бд список всех авторов */
  19. var list = await StickerDao.GetAuthorsList();
  20. var totalCount = list.Count;
  21. list = list.GetRange((page - 1) * 10, list.Count >= page * 10 ? 10 : list.Count % 10);
  22. if (list.Count == 0)
  23. {
  24. User.Session.UndoCurrentCommand();
  25. await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.page_not_found);
  26. }
  27. /* Заменяем сообщение меню на сообщение со списком */
  28. else
  29. await MessageController.EditMessage(User, CallbackMessageId, Messages.choose_author,
  30. Keyboard.GetAuthorsKeyboard(list, Keyboard.GetPagePanel(page, totalCount, CommandText)));
  31. }
  32. public AuthorsMenu() { }
  33. public AuthorsMenu(UserEntity user, Update update) : base(user, update) { }
  34. }
  35. }