To finalize my mini series on the object store I’d like to put a simple page comments library. The library takes care of everything that is required for you to post and retrieve a list of comments. It does not (so far) offer any moderation functionality or even facilitates any comments removal. It’s something that I will most probably be added in the process.

I am in the process of figuring out how I can contribute it through the Community EpiCode effort on CodeResort. As soon as I get some answers from Steve, I’ll get it uploaded there. In the mean time let me document how to start using it.

For the time being you can get the code here or the compiled library with the intellisense help form here.

Posting comments

the posting is somewhat manual in terms of not having a pre-made control for it. Which if you look at the code does not have much sense to have.

All you need to do is put two edit boxes on a page and a submit button, and then bind the action of the submit button to a code looking somewhat like:

protected void SubmitComment(object sender, System.EventArgs e)
{
    IPageComment newComment =
        PageCommentFactory.createInstance(Guid.Empty,
        string.Format("CommentForPage{0}", CurrentPage.PageLink.ID),
        CurrentPage.PageLink.ID,
        SubjectTextBox.Text, ContentTextBox.Text, DateTime.Now, false, true, false);
    newComment.Save();
}

I honestly don’t feel like making a custom control for creating those would be worthwhile since no one would end up using it anyway.

The listing of comments however…

The comments can be accessed in a number of ways.

Probably the easiest one would be by using the templated control I’ve written in the library, which is a simple descendant of the ASP.NET repeater. The page could would look something like:

...

<%@ Register TagPrefix="CognifideControls"
    Namespace="Cognifide.EPiServerControls.PageComments.Controls"
    Assembly="Cognifide.EPiServerControls.PageComments" %>

...


<CognifideControls:PageCommentsList ID="CommentControl" runat="server"
    PageLinkIdProperty="<%# CurrentPage.PageLink.ID %>">
    <ItemTemplate> 
        <b><%# CommentControl.CurrentComment.Title %></b> - 
        <%# CommentControl.CurrentComment.SubmitDate.ToString() %><br />
        <%# CommentControl.CurrentComment.Content%><br /><br />
    </ItemTemplate>
</CognifideControls:PageCommentsList>

I’ve chose this way since that’s pretty much the standard way of adding controls that are defined in Episerver and just generally ASP.Net.

But nothing stops you from accessing the comments directly,  and then filling in the data for the repeater yourself like:

<asp:Repeater ID="CurrentComments" runat="server" 
    OnItemDataBound="CurrentComments_ItemDataBound"> 
    <ItemTemplate>
        <b><asp:Label ID="CommentSubjectLabel" runat="server"></asp:Label></b><br />
        <asp:Label ID="CommentContentLabel" runat="server"></asp:Label><br /><br />
    </ItemTemplate>
</asp:Repeater>

And then in the code-behind

protected void Page_Load(object sender, EventArgs e)
{
    List<IPageComment> comments =
        PageCommentFactory.GetCommentsForPage(CurrentPage.PageLink.ID, 
        DateTime.MinValue, DateTime.MaxValue, true);
    CurrentComments.DataSource = comments;
    CurrentComments.DataBind();
}

protected void CurrentComments_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    IPageComment comment = (e.Item.DataItem as IPageComment);
    Label commentSubjectLabel = (Label)e.Item.FindControl("CommentSubjectLabel");
    if (comment != null)
    {
        commentSubjectLabel.Text = comment.Title;
    }
 
    Label commentContentLabel = (Label)e.Item.FindControl("CommentContentLabel");
    if (comment != null)
    {
        commentContentLabel.Text = comment.Content;
    }
}

That’s pretty much what my implementation does anyway.

I hope to be able to put it up on CodeResort soon so that we can see what else could be done. Additionally my library allows for replacing the persistence provider, which we will probably have implemented using nHibernate to test its speed versus the ObjectStore. Should you be interested in providing some help with this, or adding come moderation code to the admin side of the site on top of the interface, it would definitely be greatly appreciated.

I have started implementing the Property based on the code so that it can be easily displayed on the editor’s page, but for now, I’ll have to delay it since we’ve got some other stuff to do related to the project I’m currently working on.

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.67 out of 5)
Loading...



This entry (Permalink) was posted on Friday, April 6th, 2007 at 1:45 pm and is filed under ASP.NET, C#, Downloadable, EPiServer, Software Development, Web applications. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response , or trackback from your own site.