public ActionResult TopicsByTag(string tag, int? p) { using (UnitOfWorkManager.NewUnitOfWork()) { var allowedCategories = _categoryService.GetAllowedCategories(UsersRole); var settings = SettingsService.GetSettings(); var tagModel = _topicTagService.Get(tag); // Set the page index var pageIndex = p ?? 1; // Get the topics var topics = _topicService.GetPagedTopicsByTag(pageIndex, settings.TopicsPerPage, int.MaxValue, tag, allowedCategories); // See if the user has subscribed to this topic or not var isSubscribed = UserIsAuthenticated && (_tagNotificationService.GetByUserAndTag(LoggedOnReadOnlyUser, tagModel).Any()); // Get the Topic View Models var topicViewModels = ViewModelMapping.CreateTopicViewModels(topics, RoleService, UsersRole, LoggedOnReadOnlyUser, allowedCategories, settings); // create the view model var viewModel = new TagTopicsViewModel { Topics = topicViewModels, PageIndex = pageIndex, TotalCount = topics.TotalCount, TotalPages = topics.TotalPages, Tag = tag, IsSubscribed = isSubscribed, TagId = tagModel.Id }; return View(viewModel); } }
public ActionResult TopicsByTag(string tag, int? p) { using (UnitOfWorkManager.NewUnitOfWork()) { // Set the page index var pageIndex = p ?? 1; // Get the topics var topics = _topicService.GetPagedTopicsByTag(pageIndex, SettingsService.GetSettings().TopicsPerPage, SiteConstants.ActiveTopicsListSize, tag); // Get the Topic View Models var topicViewModels = ViewModelMapping.CreateTopicViewModels(topics, RoleService, UsersRole, LoggedOnUser, SettingsService.GetSettings()); // create the view model var viewModel = new TagTopicsViewModel { Topics = topicViewModels, PageIndex = pageIndex, TotalCount = topics.TotalCount, TotalPages = topics.TotalPages, Tag = tag }; return View(viewModel); } }
public ActionResult TopicsByTag(string tag, int? p) { using (UnitOfWorkManager.NewUnitOfWork()) { // Set the page index var pageIndex = p ?? 1; // Get the topics var topics = _topicService.GetPagedTopicsByTag(pageIndex, SettingsService.GetSettings().TopicsPerPage, AppConstants.ActiveTopicsListSize, tag); // Get all the categories for this topic collection var categories = topics.Select(x => x.Category).Distinct(); // create the view model var viewModel = new TagTopicsViewModel { Topics = topics, AllPermissionSets = new Dictionary<Category, PermissionSet>(), PageIndex = pageIndex, TotalCount = topics.TotalCount, User = LoggedOnUser, Tag = tag }; // loop through the categories and get the permissions foreach (var category in categories) { var permissionSet = RoleService.GetPermissions(category, UsersRole); viewModel.AllPermissionSets.Add(category, permissionSet); } return View(viewModel); } }