コード例 #1
0
        public virtual ActionResult HotTopics(DateTime?from, DateTime?to, int?amountToShow)
        {
            if (amountToShow == null)
            {
                amountToShow = 5;
            }

            var loggedOnReadOnlyUser = User.GetMembershipUser(MembershipService);
            var loggedOnUsersRole    = loggedOnReadOnlyUser.GetRole(RoleService);

            var fromString = from != null?Convert.ToDateTime(from).ToShortDateString() : null;

            var toString = to != null?Convert.ToDateTime(to).ToShortDateString() : null;

            var cacheKey  = string.Concat("HotTopics", loggedOnUsersRole.Id, fromString, toString, amountToShow);
            var viewModel = CacheService.Get <HotTopicsViewModel>(cacheKey);

            if (viewModel == null)
            {
                // Allowed Categories
                var allowedCategories = _categoryService.GetAllowedCategories(loggedOnUsersRole);

                // Get the topics
                var topics = _topicService.GetPopularTopics(from, to, allowedCategories, (int)amountToShow);

                topics = topics.Where(x => x.Pending != null && !x.Pending.GetValueOrDefault()).ToList();
                // Get the Topic View Models
                var topicViewModels = ViewModelMapping.CreateTopicViewModels(topics.ToList(), RoleService,
                                                                             loggedOnUsersRole, loggedOnReadOnlyUser, allowedCategories, SettingsService.GetSettings(),
                                                                             _postService, _notificationService, _pollService, _voteService, _favouriteService);

                // create the view model
                viewModel = new HotTopicsViewModel
                {
                    Topics = topicViewModels
                };
                CacheService.Set(cacheKey, viewModel, CacheTimes.TwoHours);
            }

            return(PartialView(viewModel));
        }
コード例 #2
0
ファイル: TopicController.cs プロジェクト: NineMvp/mvcforum
        public ActionResult HotTopics(DateTime?from, DateTime?to, int?amountToShow)
        {
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                if (amountToShow == null)
                {
                    amountToShow = 5;
                }

                // Get the topics
                var topics = _topicService.GetPopularTopics(from, to, (int)amountToShow);

                // Get the Topic View Models
                var topicViewModels = ViewModelMapping.CreateTopicViewModels(topics.ToList(), RoleService, UsersRole, LoggedOnUser, SettingsService.GetSettings());

                // create the view model
                var viewModel = new HotTopicsViewModel
                {
                    Topics = topicViewModels
                };

                return(PartialView(viewModel));
            }
        }
コード例 #3
0
ファイル: TopicController.cs プロジェクト: lenwen/mvcforum
        public ActionResult HotTopics(DateTime? from, DateTime? to, int? amountToShow)
        {
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                if (amountToShow == null)
                {
                    amountToShow = 5;
                }

                var fromString = from != null ? Convert.ToDateTime(from).ToShortDateString() : null;
                var toString = to != null ? Convert.ToDateTime(to).ToShortDateString() : null;

                var cacheKey = string.Concat("HotTopics", UsersRole.Id, fromString, toString, amountToShow);
                var viewModel = CacheService.Get<HotTopicsViewModel>(cacheKey);
                if (viewModel == null)
                {
                    // Allowed Categories
                    var allowedCategories = _categoryService.GetAllowedCategories(UsersRole);

                    // Get the topics
                    var topics = _topicService.GetPopularTopics(from, to, allowedCategories, (int)amountToShow);

                    // Get the Topic View Models
                    var topicViewModels = ViewModelMapping.CreateTopicViewModels(topics.ToList(), RoleService, UsersRole, LoggedOnReadOnlyUser, allowedCategories, SettingsService.GetSettings());

                    // create the view model
                    viewModel = new HotTopicsViewModel
                    {
                        Topics = topicViewModels
                    };
                    CacheService.Set(cacheKey, viewModel, CacheTimes.TwoHours);
                }

                return PartialView(viewModel);
            }
        }