TechGeek

Untitled

May 23rd, 2020
1,468
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public async Task<IList<Item>> GetAsync(IList<int> clientIds, int processId, int proc, Kyte kt)
  2.     {
  3.         var clientMaps = await ProcessCassQueries(clientIds, (ct, batch) => mapper.SingleOrDefaultAsync<ItemMapPoco>(itemMapStmt, batch), "GetPIMValue");
  4.  
  5.         if (clientMaps == null || clientMaps.Count <= 0)
  6.         {
  7.             return null;
  8.         }
  9.  
  10.         var itemIds = clientMaps.SelectMany(x => x.ItemIds).Where(y => y != null).ToList();
  11.  
  12.         var itemsTask = ProcessCassQueries(itemIds, (ct, batch) => mapper.SingleOrDefaultAsync<ItemPoco>(itemSelectStmt, batch), "GetAsync");
  13.  
  14.         var itemProTask = ProcessCassQueries(itemIds, (ct, batch) => mapper.SingleOrDefaultAsync<ItemProPoco>(itemProStmt, batch, processId), "GetIPValue");
  15.  
  16.         var items = await itemsTask;
  17.         if (items.Count <= 0)
  18.         {
  19.             return null;
  20.         }
  21.  
  22.         var itmDictionary = items.ToDictionary(dto => dto.ItemId, dto => rpm.MapToItem(dto, proc));
  23.         var itmProDict = itemIds.ToDictionary<int, int, ItemProPoco>(id => id, id => null);
  24.         var holder = new List<int>();
  25.  
  26.         var itemPrices = await itemProTask;
  27.         itemPrices.ForEach(i => { if (i != null) itmProDict[i.ItemId] = i; });
  28.         foreach (var ip in itmProDict) if (ip.Value == null) holder.Add(ip.Key);
  29.  
  30.         if (holder.Count > 0)
  31.         {
  32.             var ipHolder = await ProcessCassQueries(itemIds, (ct, batch) => mapper.SingleOrDefaultAsync<ItemProPoco>(itemProStmt, batch, kt.Pid), "GetIPValue");
  33.             ipHolder.ToList().ForEach(ipf => { if (ipf != null) itmProDict[ipf.ItemId] = ipf; });
  34.         }
  35.  
  36.         return itmDictionary.Select(kvp =>
  37.         {
  38.             itmProDict.TryGetValue(kvp.Key, out var ip);
  39.  
  40.             if (kvp.Value != null)
  41.             {
  42.                 rpm.convert(ip, kvp.Value);
  43.                 return kvp.Value;
  44.             }
  45.  
  46.             return null;
  47.         }).Where(s => s != null).ToList();
  48.     }
RAW Paste Data