rendered paste bodynamespace 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<IForumTopicService>();
IForumPostService _post = WindsorHelper.Resolve<IForumPostService>();
ForumTopic topic = _topic.Find(topicId);
PagerList<ForumPost> 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("<tr>");
html.Append("<td class=\"image\"></td>");
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(
"<td class=\"{0}\">{1}<a href=\"{2}\">{3}</a></td>",
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("<td class=\"date\">{0}</td>", post.DateCreated.ToString("MM/dd/yyyy h:mm tt"));
html.AppendFormat(
"<td class=\"poster\"><a href=\"{0}\">{1}</a></td>",
UrlHelper.UrlBuilder.BuildRouteUrl(Controller.Context.UrlInfo, "member.view", DictHelper.Create(string.Format("id={0}", post.Author.MemberID))),
post.Author.Name
);
html.Append("<td class=\"checkbox\"><input type=\"checkbox\" name=\"\" /></td>");
html.Append("</tr>");
}
#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
}
}