OpenAuthorPackMenu.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.packs_count_zero, true);
  21. else
  22. {
  23. var page = int.Parse(CallbackData.Split('=')[1]);
  24. var totalCount = packs.Count;
  25. packs = packs.GetRange((page - 1) * 10, packs.Count >= page * 10 ? 10 : packs.Count % 10);
  26. if (packs.Count == 0)
  27. await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.page_not_found);
  28. else
  29. await MessageController.EditMessage(User, Messages.choose_author,
  30. await Keyboard.GetUserPacksKeyboard(packs, Keyboard.GetPagePanel(page, totalCount, CommandText)));
  31. }
  32. }
  33. public OpenAuthorPackMenu() { }
  34. public OpenAuthorPackMenu(UserEntity user, Update update) : base(user, update) { }
  35. }
  36. }