namespace NetCoders.Portal.Core.Helpers { using System.Text; using Castle.MonoRail.Framework.Helpers; using NetCoders.Portal.Core.Services; using NetCoders.Portal.Model.Forum; public class ForumHelper : AbstractHelper { #region BuildPostsThreaded public string BuildPostsThreaded(int topicId, int page) { return BuildPostsThreaded(topicId, page, 0); } public string BuildPostsThreaded(int topicId, int page, int selectedId) { IForumTopicService _topic = WindsorHelper.Resolve(); IForumPostService _post = WindsorHelper.Resolve(); ForumTopic topic = _topic.Find(topicId); PagerList posts = _post.FindAll_Threaded(topic.TopicID, topic.Post.PostID, page, 10); StringBuilder html = new StringBuilder(); foreach (ForumPost post in posts) { AddPost(html, post, 1, selectedId); if (post.Posts.Count > 0) { AddPosts(html, post, selectedId); } } return html.ToString(); } #endregion #region AddPost public void AddPost(StringBuilder html, ForumPost post, int count, int selectedId) { html.Append(""); html.Append(""); string indent = "  "; for (int i = 1; i <= count; i++) { indent += "  "; } string css = "title"; if (selectedId > 0) { if (post.PostID == selectedId) { css = "title-selected"; } } html.AppendFormat( "{1}{3}", css, indent, UrlHelper.UrlBuilder.BuildRouteUrl( Controller.Context.UrlInfo, "forum.topic.view.mode", DictHelper.Create( "mode=threaded", string.Format("id={0}", post.Topic.TopicID), string.Format("postId={0}", post.PostID), "page=1" ) ), post.Title ); html.AppendFormat("{0}", post.DateCreated.ToString("MM/dd/yyyy h:mm tt")); html.AppendFormat( "{1}", UrlHelper.UrlBuilder.BuildRouteUrl(Controller.Context.UrlInfo, "member.view", DictHelper.Create(string.Format("id={0}", post.Author.MemberID))), post.Author.Name ); html.Append(""); html.Append(""); } #endregion #region AddPosts public void AddPosts(StringBuilder html, ForumPost item, int selectedId) { foreach (ForumPost post in item.Posts) { if (item.Indent == 0) { post.Indent = 1 * 2; } else { post.Indent = item.Indent + 2; } AddPost(html, post, post.Indent, selectedId); if (post.Posts.Count > 0) { AddPosts(html, post, selectedId); } } } #endregion } }