pszczyg

ToDictionary3

Oct 3rd, 2019
286
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  public void ReloadCache(TransactionArgs transactionArgs = null)
  2.         {
  3.             List<ATMTaskTypePriorityEntry> taskTypePriorityEntries = _taskTypePriorityDatabaseAccess.GetAllPriorities(transactionArgs);
  4.             TaskTypePriorities = ConvertTableEntriesToTaskTypePriorities(taskTypePriorityEntries);
  5.         }
  6.  
  7.         private List<ATMTaskTypePriorities> ConvertTableEntriesToTaskTypePriorities(List<ATMTaskTypePriorityEntry> taskTypePriorityEntries)
  8.         {
  9.             List<IGrouping<long, ATMTaskTypePriorityEntry>> entriesByTaskTypeId = taskTypePriorityEntries.GroupBy(entry => entry.TaskTypeDbId).ToList(); //group entries by TaskTypeDbId
  10.             List<ATMTaskTypePriorities> prioritiesList = new List<ATMTaskTypePriorities>(entriesByTaskTypeId.Count); //we know how long should list be, so initialize it accordingly
  11.             foreach (var entryGroup in entriesByTaskTypeId)
  12.             {
  13.                 Dictionary<int, ATMTaskPriorities> taskTypePriorities = new Dictionary<int, ATMTaskPriorities>();
  14.                 foreach (var entry in entryGroup)
  15.                     taskTypePriorities[entry.EventThreshold] = entry.Priority; //this is design decision - if entries duplicates, last will win
  16.                
  17.                 prioritiesList.Add(new ATMTaskTypePriorities(entryGroup.Key, taskTypePriorities));
  18.             }
  19.  
  20.             return prioritiesList;
  21.         }
RAW Paste Data