Browse Source

Auction filtering fix

Tigran 4 years ago
parent
commit
3ad5e20cc7

+ 2 - 2
CardCollector.sln.DotSettings.user

@@ -3,13 +3,13 @@
   <Assembly Path="C:\Users\DarkGolly\.nuget\packages\telegram.bot\17.0.0-alpha.3\lib\netcoreapp3.1\Telegram.Bot.dll" />
 &lt;/AssemblyExplorer&gt;</s:String>
 	
-	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FCommand/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FCommand/@EntryIndexedValue">False</s:Boolean>
 	
 	
 	
 	
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FMessages/@EntryIndexedValue">False</s:Boolean>
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FSortingTypes/@EntryIndexedValue">False</s:Boolean>
-	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FText/@EntryIndexedValue">False</s:Boolean>
+	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=CardCollector_002FResources_002FText/@EntryIndexedValue">True</s:Boolean>
 	
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>

+ 1 - 1
CardCollector/Commands/CallbackQuery/BackToFiltersMenu.cs

@@ -23,7 +23,7 @@ namespace CardCollector.Commands.CallbackQuery
             /* Редактируем сообщение */
             var message = await MessageController.EditMessage(User, CallbackMessageId, 
                     text, Keyboard.GetSortingMenu(User.Session.State));
-            User.Session.Messages.Add(message.MessageId);
+            if (!User.Session.Messages.Contains(message.MessageId)) User.Session.Messages.Add(message.MessageId);
         }
         
         public BackToFiltersMenu() { }

+ 3 - 3
CardCollector/Commands/CallbackQuery/ConfirmBuyingQuery.cs

@@ -19,9 +19,9 @@ namespace CardCollector.Commands.CallbackQuery
                 await MessageController.AnswerCallbackQuery(User, Update.CallbackQuery!.Id, Messages.not_enougth_gems);
             else
             {
-                var text = $"{Messages.confirm_buying}\n{User.Session.SelectedSticker.Count}{Text.items}" +
-                           $" {Text.per} {coinsPrice}{Text.coin} / {gemsPrice}{Text.gem}" +
-                           $"\n{Text.total}: {coinsPrice*User.Session.SelectedSticker.Count}{Text.coin} / {gemsPrice*User.Session.SelectedSticker.Count}{Text.gem}" +
+                var text = $"{Messages.confirm_buying}\n" +
+                           $"{User.Session.SelectedSticker.Count}{Text.items} {Text.per} " +
+                           $"{coinsPrice*User.Session.SelectedSticker.Count}{Text.coin} / {gemsPrice*User.Session.SelectedSticker.Count}{Text.gem}" +
                            $"\n{Messages.are_you_sure}";
                 await MessageController.EditMessage(User, CallbackMessageId, text, Keyboard.GetConfirmationKeyboard(Command.buy_sticker));
             }

+ 2 - 3
CardCollector/Commands/InlineQuery/ShowTradersInBotChat.cs

@@ -1,5 +1,4 @@
-using System.Linq;
-using System.Threading.Tasks;
+using System.Threading.Tasks;
 using CardCollector.Controllers;
 using CardCollector.DataBase.Entity;
 using CardCollector.Resources;
@@ -16,7 +15,7 @@ namespace CardCollector.Commands.InlineQuery
             var filter = Update.InlineQuery!.Query;
             // Получаем список продавцов
             var traders = await AuctionController.GetTradersList(filter, User.Session.SelectedSticker.Id);
-            var results = traders.ToTelegramResults(Command.buy_sticker);
+            var results = User.Session.Filters.ApplyTo(traders).ToTelegramResults(Command.buy_sticker);
             // Посылаем пользователю ответ на его запрос
             await MessageController.AnswerInlineQuery(InlineQueryId, results);
         }

+ 0 - 1
CardCollector/Controllers/MessageController.cs

@@ -149,7 +149,6 @@ namespace CardCollector.Controllers
             }
             catch (Exception e)
             {
-                LogOutWarning("Can't edit message text " + e.Message);
                 return await SendMessage(user, message, keyboard);
             }
             return new TgMessage();

+ 7 - 0
CardCollector/DataBase/EntityDao/AuctionDao.cs

@@ -59,6 +59,13 @@ namespace CardCollector.DataBase.EntityDao
             await Instance.SaveChangesAsync();
         }
 
+        public static IEnumerable<int> GetPriceList(string stickerId, bool coins)
+        {
+            return Table
+                .Where(i => i.StickerId == stickerId)
+                .Select(i => coins ? i.PriceCoins : i.PriceGems);
+        }
+
         public static async Task<int> GetQuantity(int productId)
         {
             return (await Table.FirstAsync(item => item.Id == productId)).Quantity;

+ 32 - 6
CardCollector/Extensions.cs

@@ -59,7 +59,7 @@ namespace CardCollector
             return result;
         }
 
-        public static IEnumerable<StickerEntity> ApplyTo (this Dictionary<string, object> dict, 
+        public static IEnumerable<StickerEntity> ApplyTo(this Dictionary<string, object> dict,
             IEnumerable<StickerEntity> list, UserState state)
         {
             /* Фильтруем по автору */
@@ -72,19 +72,28 @@ namespace CardCollector
             if (dict[Command.emoji] is string emoji && emoji != "")
                 list = list.Where(item => item.Emoji.Contains(emoji));
             /* Если пользвователь не находится в меню коллекции, то фильтруем по цене */
-            if (state is not UserState.CollectionMenu){
+            if (state is not UserState.CollectionMenu)
+            {
                 /* Фильтруем по цене монет ОТ */
                 if (dict[Command.price_coins_from] is int PCF && PCF != 0)
-                    list = list.Where(item => item.PriceCoins >= PCF);
+                    list = list.Where(item => state == UserState.AuctionMenu
+                        ? AuctionDao.GetPriceList(item.Id, true).Any(i => i >= PCF)
+                        : item.PriceCoins >= PCF);
                 /* Фильтруем по цене монет ДО */
                 if (dict[Command.price_coins_to] is int PCT && PCT != 0)
-                    list = list.Where(item => item.PriceCoins <= PCT);
+                    list = list.Where(item => state == UserState.AuctionMenu
+                        ? AuctionDao.GetPriceList(item.Id, true).Any(i => i <= PCT)
+                        : item.PriceCoins <= PCT);
                 /* Фильтруем по цене алмазов ОТ */
                 if (dict[Command.price_gems_from] is int PGF && PGF != 0)
-                    list = list.Where(item => item.PriceGems >= PGF);
+                    list = list.Where(item => state == UserState.AuctionMenu
+                        ? AuctionDao.GetPriceList(item.Id, false).Any(i => i >= PGF)
+                        : item.PriceGems >= PGF);
                 /* Фильтруем по цене адмазов ДО */
                 if (dict[Command.price_gems_to] is int PGT && PGT != 0)
-                    list = list.Where(item => item.PriceGems <= PGT);
+                    list = list.Where(item => state == UserState.AuctionMenu
+                        ? AuctionDao.GetPriceList(item.Id, false).Any(i => i <= PGT)
+                        : item.PriceGems <= PGT);
             }
             /* Сортируем список, если тип сортировки установлен */
             if (dict[Command.sort] is not string sort || sort == SortingTypes.None) return list;
@@ -104,6 +113,23 @@ namespace CardCollector
             }
             return list;
         }
+
+        public static IEnumerable<TraderInformation> ApplyTo(this Dictionary<string, object> dict, IEnumerable<TraderInformation> list)
+        {
+            /* Фильтруем по цене монет ОТ */
+            if (dict[Command.price_coins_from] is int PCF && PCF != 0)
+                list = list.Where(item => item.PriceCoins >= PCF);
+            /* Фильтруем по цене монет ДО */
+            if (dict[Command.price_coins_to] is int PCT && PCT != 0)
+                list = list.Where(item => item.PriceCoins <= PCT);
+            /* Фильтруем по цене алмазов ОТ */
+            if (dict[Command.price_gems_from] is int PGF && PGF != 0)
+                list = list.Where(item => item.PriceGems >= PGF);
+            /* Фильтруем по цене адмазов ДО */
+            if (dict[Command.price_gems_to] is int PGT && PGT != 0)
+                list = list.Where(item => item.PriceGems <= PGT);
+            return list;
+        }
         
         public static string ToMessage(this Dictionary<string, object> dict, UserState state)
         {