Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. public static List<SimpleKeyValue<int?, string>> ListDictionaryItemsAsKeyValueByDictionaryCodename(Dictionaries.Codename DictionaryCodenameItem,int? SelectedKey = null, ICacheAssistance Cache = null)
  2. {
  3. if(Cache == null)
  4. {
  5. Cache = new MemoryCacheAssistance();
  6. }
  7.  
  8. var Items = Cache.GetDataFromCache<List<SimpleKeyValue<int?, string>>>(DictionaryCodenameItem.DictionaryName);
  9. if (Items == null)
  10. {
  11. Items = ListDictionaries(Level: 1, DictionaryCode: DictionaryCodenameItem.DictionaryCode).Select(Item => new SimpleKeyValue<int?, string> { Key = Item.DictionaryID, Value = Item.Caption }).ToList();
  12. if (Items != null)
  13. {
  14. Cache.SetDataToCache(DictionaryCodenameItem.DictionaryName, Items, DateTime.Now.AddMinutes(AppSettings.CacheDurationInSecondsDefault));
  15. }
  16. }
  17.  
  18. var ItemsCloned = Items.Clone();
  19. if (SelectedKey.HasValue)
  20. {
  21. var SelectedItem = ItemsCloned.Find(Item => Item.Key == SelectedKey);
  22. if (SelectedItem != null)
  23. {
  24. SelectedItem.IsSelected = true;
  25. }
  26. }
  27.  
  28. return ItemsCloned;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement