Ejemplo n.º 1
0
        // Update categories stats
        private void SaveCategoryStats()
        {
            var unitOfWorkAsync = _container.Resolve <IUnitOfWorkAsync>();

            var categoryCountDctionary = ListingService.GetCategoryCount();

            foreach (var item in categoryCountDctionary)
            {
                var categoryStatQuery = CategoryStatService.Query(x => x.CategoryID == item.Key.ID).Select();

                var categoryStat = categoryStatQuery.FirstOrDefault();

                if (categoryStat != null)
                {
                    categoryStat.Count       = item.Value;
                    categoryStat.ObjectState = Repository.Pattern.Infrastructure.ObjectState.Modified;
                }
                else
                {
                    CategoryStatService.Insert(new CategoryStat()
                    {
                        CategoryID  = item.Key.ID,
                        Count       = item.Value,
                        ObjectState = Repository.Pattern.Infrastructure.ObjectState.Added
                    });
                }
            }

            unitOfWorkAsync.SaveChanges();
        }
Ejemplo n.º 2
0
        public object GetCachedItem(CacheKeys CacheKeyName)
        {
            lock (_lock)
            {
                if (!MainCache.Contains(CacheKeyName.ToString()))
                {
                    switch (CacheKeyName)
                    {
                    case CacheKeys.Settings:
                        var setting = SettingService.Queryable().FirstOrDefault();
                        UpdateCache(CacheKeys.Settings, setting);
                        break;

                    case CacheKeys.SettingDictionary:
                        var settingDictionary = SettingDictionaryService.Queryable().ToList();
                        UpdateCache(CacheKeys.SettingDictionary, settingDictionary);
                        break;

                    case CacheKeys.Categories:
                        var categories = CategoryService.Queryable().Where(x => x.Enabled).OrderBy(x => x.Ordering).ToList();
                        UpdateCache(CacheKeys.Categories, categories);
                        break;

                    case CacheKeys.ListingTypes:
                        var ListingTypes = ListingTypeService.Query().Include(x => x.CategoryListingTypes).Select().ToList();
                        UpdateCache(CacheKeys.ListingTypes, ListingTypes);
                        break;

                    case CacheKeys.ContentPages:
                        var contentPages = ContentPageService.Queryable().Where(x => x.Published).OrderBy(x => x.Ordering).ToList();
                        UpdateCache(CacheKeys.ContentPages, contentPages);
                        break;

                    case CacheKeys.EmailTemplates:
                        var emailTemplates = EmailTemplateService.Queryable().ToList();
                        UpdateCache(CacheKeys.EmailTemplates, emailTemplates);
                        break;

                    case CacheKeys.Statistics:
                        SaveCategoryStats();

                        var statistics = new Statistics();
                        statistics.CategoryStats = CategoryStatService.Query().Include(x => x.Category).Select().ToList();

                        statistics.ListingCount     = ListingService.Queryable().Count();
                        statistics.UserCount        = AspNetUserService.Queryable().Count();
                        statistics.OrderCount       = OrderService.Queryable().Count();
                        statistics.TransactionCount = 0;

                        statistics.ItemsCountDictionary = ListingService.GetItemsCount(DateTime.Now.AddDays(-10));

                        UpdateCache(CacheKeys.Statistics, statistics);
                        break;

                    default:
                        break;
                    }
                }
                ;

                return(MainCache[CacheKeyName.ToString()] as Object);
            }
        }