Exemplo n.º 1
0
        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);
                var topics = _topicService.GetPopularTopics(from, to);

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

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

                return PartialView(viewModel);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }