OpenAuthorPackMenu.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Linq;
  2. using System.Threading.Tasks;
  3. using CardCollector.Controllers;
  4. using CardCollector.DataBase.Entity;
  5. using CardCollector.DataBase.EntityDao;
  6. using CardCollector.Resources;
  7. using Telegram.Bot.Types;
  8. namespace CardCollector.Commands.CallbackQuery
  9. {
  10. public class OpenAuthorPackMenu : CallbackQueryCommand
  11. {
  12. protected override string CommandText => Command.open_author_pack_menu;
  13. protected override bool ClearMenu => false;
  14. protected override bool AddToStack => true;
  15. public override async Task Execute()
  16. {
  17. var packs = (await UserPacksDao.GetUserPacks(User.Id))
  18. .Where(item => item.Count > 0 && item.PackId != 1).ToList();
  19. if (packs.Count == 0)
  20. {
  21. User.Session.PopLast();
  22. await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.packs_count_zero, true);
  23. }
  24. else
  25. {
  26. var page = int.Parse(CallbackData.Split('=')[1]);
  27. var totalCount = packs.Count;
  28. packs = packs.GetRange((page - 1) * 10, packs.Count >= page * 10 ? 10 : packs.Count % 10);
  29. if (packs.Count == 0)
  30. {
  31. User.Session.PopLast();
  32. await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.page_not_found);
  33. }
  34. else
  35. await MessageController.EditMessage(User, CallbackMessageId, Messages.choose_author,
  36. await Keyboard.GetUserPacksKeyboard(packs, Keyboard.GetPagePanel(page, totalCount, CommandText)));
  37. }
  38. }
  39. public OpenAuthorPackMenu() { }
  40. public OpenAuthorPackMenu(UserEntity user, Update update) : base(user, update) { }
  41. }
  42. }