Tigran 4 gadi atpakaļ
vecāks
revīzija
1b814ca07e

+ 6 - 5
CardCollector/DataBase/EntityDao/AuctionDao.cs

@@ -1,5 +1,8 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Linq;
+using System.Linq.Expressions;
+using System.Threading;
 using System.Threading.Tasks;
 using CardCollector.DataBase.Entity;
 using CardCollector.Others;
@@ -59,11 +62,9 @@ namespace CardCollector.DataBase.EntityDao
             await Instance.SaveChangesAsync();
         }
 
-        public static IEnumerable<int> GetPriceList(string stickerId, bool coins)
+        public static bool HaveAny(string stickerId, Expression<Func<AuctionEntity, bool>> source)
         {
-            return Table
-                .Where(i => i.StickerId == stickerId)
-                .Select(i => coins ? i.PriceCoins : i.PriceGems);
+            return Table.Where(i => i.StickerId == stickerId).AnyAsync(source).Result;
         }
 
         public static async Task<int> GetQuantity(int productId)

+ 6 - 4
CardCollector/Extensions.cs

@@ -76,23 +76,25 @@ namespace CardCollector
             {
                 /* Фильтруем по цене монет ОТ */
                 if (dict[Command.price_coins_from] is int PCF && PCF != 0)
+                {
                     list = list.Where(item => state == UserState.AuctionMenu
-                        ? AuctionDao.GetPriceList(item.Id, true).Any(i => i >= PCF)
+                        ? AuctionDao.HaveAny(item.Id, i => i.PriceCoins >= PCF)
                         : item.PriceCoins >= PCF);
+                }
                 /* Фильтруем по цене монет ДО */
                 if (dict[Command.price_coins_to] is int PCT && PCT != 0)
                     list = list.Where(item => state == UserState.AuctionMenu
-                        ? AuctionDao.GetPriceList(item.Id, true).Any(i => i <= PCT)
+                        ? AuctionDao.HaveAny(item.Id, i => i.PriceCoins <= PCT)
                         : item.PriceCoins <= PCT);
                 /* Фильтруем по цене алмазов ОТ */
                 if (dict[Command.price_gems_from] is int PGF && PGF != 0)
                     list = list.Where(item => state == UserState.AuctionMenu
-                        ? AuctionDao.GetPriceList(item.Id, false).Any(i => i >= PGF)
+                        ? AuctionDao.HaveAny(item.Id, i => i.PriceCoins >= PGF)
                         : item.PriceGems >= PGF);
                 /* Фильтруем по цене адмазов ДО */
                 if (dict[Command.price_gems_to] is int PGT && PGT != 0)
                     list = list.Where(item => state == UserState.AuctionMenu
-                        ? AuctionDao.GetPriceList(item.Id, false).Any(i => i <= PGT)
+                        ? AuctionDao.HaveAny(item.Id, i => i.PriceCoins <= PGT)
                         : item.PriceGems <= PGT);
             }
             /* Сортируем список, если тип сортировки установлен */