コード例 #1
0
        public async Task <Dictionary <string, KeyValuePair <int, string> > > GetAllResourceValuesAsync(int languageId)
        {
            var key = string.Format(LocalizationDefaults.LocaleStringResourcesAllCacheKey, languageId);

            var result = await _memoryCache.GetOrCreateAsync(key, async entry =>
            {
                entry.SetOptions(PrepareEntryOptions());
                var resources = (await _repository.GetResourcesByLanguageIdAsync(languageId)).ToList();
                Dictionary <string, KeyValuePair <int, string> > dictionary = new Dictionary <string, KeyValuePair <int, string> >();
                resources.ForEach(x =>
                {
                    if (!dictionary.ContainsKey(x.ResourceName))
                    {
                        dictionary.Add(x.ResourceName, new KeyValuePair <int, string>(x.Id, x.ResourceValue));
                    }
                });
                return(dictionary);
            });

            return(result);
        }