BuyAuthorPackMenu.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132
  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. public class BuyAuthorPackMenu : CallbackQueryCommand
  10. {
  11. protected override string CommandText => Command.buy_author_pack_menu;
  12. protected override bool ClearMenu => false;
  13. protected override bool AddToStack => true;
  14. public override async Task Execute()
  15. {
  16. var page = int.Parse(CallbackData.Split('=')[1]);
  17. var packs = await PacksDao.GetAll();
  18. var totalCount = packs.Count;
  19. packs = packs.GetRange((page - 1) * 10, packs.Count >= page * 10 ? 10 : packs.Count % 10);
  20. if (packs.Count == 0)
  21. await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.page_not_found);
  22. else
  23. await MessageController.EditMessage(User, Messages.choose_author,
  24. Keyboard.GetShopPacksKeyboard(packs, Keyboard.GetPagePanel(page, totalCount, CommandText)));
  25. }
  26. public BuyAuthorPackMenu() { }
  27. public BuyAuthorPackMenu(UserEntity user, Update update) : base(user, update) { }
  28. }
  29. }