BuyStickerQuery.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 CardCollector.Session.Modules;
  7. using Telegram.Bot.Types;
  8. namespace CardCollector.Commands.CallbackQuery
  9. {
  10. public class BuyStickerQuery : CallbackQuery
  11. {
  12. protected override string CommandText => Command.buy_sticker;
  13. public override async Task Execute()
  14. {
  15. var auctionModule = User.Session.GetModule<AuctionModule>();
  16. if (auctionModule.Count > auctionModule.MaxCount)
  17. {
  18. await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.not_enougth_stickers);
  19. await new BackToFiltersMenu(User, Update).Execute();
  20. }
  21. else if (auctionModule.Price * auctionModule.Count > User.Cash.Gems)
  22. await MessageController.AnswerCallbackQuery(User, CallbackQueryId, Messages.not_enougth_gems);
  23. else
  24. {
  25. await auctionModule.SelectedPosition.BuyCard(auctionModule.Count);
  26. if (User.Stickers.ContainsKey(auctionModule.SelectedSticker.Md5Hash))
  27. await MessageController.AnswerCallbackQuery(User, CallbackQueryId,
  28. $"{Messages.you_collected} {await User.Cash.Payout(User.Stickers)}{Text.coin}");
  29. else
  30. await UserStickerRelationDao.AddNew(User, auctionModule.SelectedSticker, auctionModule.Count);
  31. User.Cash.Gems -= auctionModule.Price * auctionModule.Count;
  32. User.Session.ResetModule<AuctionModule>();
  33. await User.ClearChat();
  34. }
  35. }
  36. public BuyStickerQuery() { }
  37. public BuyStickerQuery(UserEntity user, Update update) : base(user, update) { }
  38. }
  39. }