Пример #1
0
 public async Task <IEnumerable <SelectListItem> > GetProjectTypeList(CancellationToken cancellationToken = default)
 {
     return(await _cache.GetOrCreateAsync(CacheHelpers.GenerateCacheKey("ProjectType"), async entry =>
     {
         entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration;
         var list = await _dbContext.ProjectTypes.ToListAsync(cancellationToken);
         return list.Select(s =>
                            new SelectListItem(
                                CultureHelper.IsArabic ? s.NameAr : s.NameEn, s.Id.ToString())).ToList();
     }));
 }
Пример #2
0
 public async Task <IEnumerable <SelectListItem> > GetBuildingList()
 {
     return(await _cache.GetOrCreateAsync(CacheHelpers.GenerateCacheKey("GetBuildingList"), async entry =>
     {
         entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration;
         var list = await _dbContext.Buildings.ToListAsync();
         return list.Select(s =>
                            new SelectListItem(
                                CultureHelper.IsArabic ? s.Number : s.Number, s.Id.ToString())).ToList();
     }));
 }
        public async Task <IDictionary <string, IList <SettingsDto> > > GetAllSettingsCached()
        {
            //cache
            return(await _cache.GetOrCreateAsync(CacheHelpers.GenerateCacheKey("SettingsAllCacheKey"), async entry =>
            {
                //we use no tracking here for performance optimization
                //anyway records are loaded only for read-only operations
                entry.SlidingExpiration = CacheHelpers.DefaultCacheDuration;
                var query = from s in _dbContext.SystemSettings
                            orderby s.Name
                            select s;
                var settings = await query.AsNoTracking().Select(s => new SettingsDto
                {
                    Id = s.Id,
                    Name = s.Name,
                    Value = s.Value,
                    GroupName = s.GroupName,
                    ValueType = s.ValueType
                }).ToListAsync();

                var dictionary = new Dictionary <string, IList <SettingsDto> >();
                foreach (var s in settings)
                {
                    var resourceName = s.Name.ToLowerInvariant();


                    if (!dictionary.ContainsKey(resourceName))
                    {
                        //first setting
                        dictionary.Add(resourceName, new List <SettingsDto>
                        {
                            s
                        });
                    }
                    else
                    {
                        //already added
                        //most probably it's the setting with the same name but for some certain store (storeId > 0)
                        dictionary[resourceName].Add(s);
                    }
                }

                return dictionary;
            }));
        }