public ActionResult Index(string urlName, int page = 1) { if (String.IsNullOrWhiteSpace(urlName)) return HttpNotFound(); var forum = _forumService.Get(urlName); if (forum == null) return this.NotFound("NotFound", null); var user = this.CurrentUser(); var permissionContext = _forumService.GetPermissionContext(forum, user); if (!permissionContext.UserCanView) { return this.Forbidden("Forbidden", null); } PagerContext pagerContext; var topics = _topicService.GetTopics(forum, permissionContext.UserCanModerate, page, out pagerContext); var container = new ForumTopicContainer {Forum = forum, Topics = topics, PagerContext = pagerContext, PermissionContext = permissionContext}; _lastReadService.GetTopicReadStatus(user, container); var adapter = new ForumAdapterFactory(forum); if (adapter.IsAdapterEnabled) { adapter.ForumAdapter.AdaptForum(this, container); if (String.IsNullOrWhiteSpace(adapter.ForumAdapter.ViewName)) return View(adapter.ForumAdapter.Model); return View(adapter.ForumAdapter.ViewName, adapter.ForumAdapter.Model); } if (forum.IsQAForum) return View("IndexQA", container); return View(container); }
public ActionResult PostLink(int id) { var includeDeleted = false; var user = this.CurrentUser(); if (user != null && user.IsInRole(PermanentRoles.Moderator)) includeDeleted = true; var post = _postService.Get(id); if (post == null || (post.IsDeleted && (user == null || !user.IsInRole(PermanentRoles.Moderator)))) return this.NotFound("NotFound", null); Topic topic; var page = _postService.GetTopicPageForPost(post, includeDeleted, out topic); var forum = _forumService.Get(topic.ForumID); var adapter = new ForumAdapterFactory(forum); if (adapter.IsAdapterEnabled) { var result = adapter.ForumAdapter.AdaptPostLink(this, post, topic, forum); if (result != null) return result; } var url = Url.Action("Topic", new {id = topic.UrlName, page}) + "#" + post.PostID; return Redirect(url); }
public ViewResult Topic(string id, int page = 1) { var topic = _topicService.Get(id); if (topic == null) return this.NotFound("NotFound", null); var forum = _forumService.Get(topic.ForumID); if (forum == null) throw new Exception(String.Format("TopicID {0} references ForumID {1}, which does not exist.", topic.TopicID, topic.ForumID)); var adapter = new ForumAdapterFactory(forum); var permissionContext = _forumService.GetPermissionContext(forum, this.CurrentUser(), topic); if (!permissionContext.UserCanView) { return this.Forbidden("Forbidden", null); } PagerContext pagerContext = null; var isSubscribed = false; var isFavorite = false; var user = this.CurrentUser(); DateTime? lastReadTime = DateTime.UtcNow; if (user != null) { lastReadTime = _lastReadService.GetLastReadTime(user, topic); isFavorite = _favoriteTopicService.IsTopicFavorite(user, topic); isSubscribed = _subService.IsTopicSubscribed(user, topic); if (isSubscribed) _subService.MarkSubscribedTopicViewed(user, topic); if (!adapter.IsAdapterEnabled || (adapter.IsAdapterEnabled && adapter.ForumAdapter.MarkViewedTopicRead)) _lastReadService.MarkTopicRead(user, topic); if (user.IsInRole(PermanentRoles.Moderator)) ViewBag.CategorizedForums = _forumService.GetCategorizedForumContainer(); } List<Post> posts; if (forum.IsQAForum) posts = _postService.GetPosts(topic, permissionContext.UserCanModerate); else posts = _postService.GetPosts(topic, permissionContext.UserCanModerate, page, out pagerContext); if (posts.Count == 0) return this.NotFound("NotFound", null); var signatures = _profileService.GetSignatures(posts); var avatars = _profileService.GetAvatars(posts); var votedIDs = _postService.GetVotedPostIDs(this.CurrentUser(), posts); var container = ComposeTopicContainer(topic, forum, permissionContext, isSubscribed, posts, pagerContext, isFavorite, signatures, avatars, votedIDs, lastReadTime); _topicViewCountService.ProcessView(topic, HttpContext); if (adapter.IsAdapterEnabled) { adapter.ForumAdapter.AdaptTopic(this, container); if (String.IsNullOrWhiteSpace(adapter.ForumAdapter.ViewName)) return View(adapter.ForumAdapter.Model); return View(adapter.ForumAdapter.ViewName, adapter.ForumAdapter.Model); } if (forum.IsQAForum) { var containerForQA = _forumService.MapTopicContainerForQA(container); return View("TopicQA", containerForQA); } return View(container); }