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 virtual async Task <ActionResult> TopicsByTag(string tag, int?p) { var loggedOnReadOnlyUser = User.GetMembershipUser(MembershipService); var loggedOnUsersRole = loggedOnReadOnlyUser.GetRole(RoleService); var allowedCategories = _categoryService.GetAllowedCategories(loggedOnUsersRole); var settings = SettingsService.GetSettings(); var tagModel = _topicTagService.Get(tag); if (tag != null) { // Set the page index var pageIndex = p ?? 1; // Get the topics var topics = await _topicService.GetPagedTopicsByTag(pageIndex, settings.TopicsPerPage, int.MaxValue, tag, allowedCategories); // See if the user has subscribed to this topic or not var isSubscribed = User.Identity.IsAuthenticated && _notificationService.GetTagNotificationsByUserAndTag(loggedOnReadOnlyUser, tagModel) .Any(); // Get the Topic View Models var topicViewModels = ViewModelMapping.CreateTopicViewModels(topics, RoleService, loggedOnUsersRole, loggedOnReadOnlyUser, allowedCategories, settings, _postService, _notificationService, _pollService, _voteService, _favouriteService); // create the view model var viewModel = new TagTopicsViewModel(); viewModel.Topics = topicViewModels; viewModel.PageIndex = pageIndex; viewModel.TotalCount = topics.TotalCount; viewModel.TotalPages = topics.TotalPages; viewModel.Tag = tag; viewModel.IsSubscribed = isSubscribed; viewModel.TagId = tagModel.Id; return(View(viewModel)); } return(ErrorToHomePage("No Such Tag")); }
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)); } }
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); } }