Converting Community Server Comments into Customer Reviews

This Community Server mod was too much fun not to blog about. Blog Post Comments as Customer Reviews. We all know users can rate a post, but displaying an individual star rating per "comment" is not something you see every day. This is what we’re talking about.

Here’s the skinny on converting comments into customer reviews. The rating widget used in the comment form is the Ajax Toolkit Rating Control. Custom WeblogPostCommentForm coolness was in adding the AjaxControlToolkit Rating control as if it were your everyday TextBox. Worked like a charm.

protected AjaxControlToolkit.Rating customerRatingStars;

protected override void AttachChildControls()
    customerRatingStars =
        CSControlUtility.Instance().FindControl(this, this.customerRatingStarsId)
        as AjaxControlToolkit.Rating;

and so forth. The star rating (1 through 5) is stored in a separate drive_Ratings table as an integer OnSubmit().

BlogPostResults result = WeblogPosts.Add(c, csContext.User, out postID);

CustomerRating customerRating = new CustomerRating();
customerRating.Rating = customerRatingStars.CurrentRating;
customerRating.PostID = postID;

For simplicity sake I created five separate star images associated with each of the possible five ratings, then a ReviewStarImage Wrapped Content control to display it.  The essential control logic being

CommunityServer.Controls.Image image = new CommunityServer.Controls.Image();
int postID = _weblogCommentPost.PostID;
int stars = Directories.GetCustomerRating(postID);
image.ImageUrl = "/images/common/stars/" + stars.ToString() + ".png";

For ultimate performance it would have been better to extend the WeblogPost object used with the reviews to retrieve the rating as part of the post, but that’s a lot of typing.  So we plop in the ReviewStarImage control as part of the WeblogFeedbackData item and we got stars.

<DRIVE:ReviewStarImage runat="server" />

Now where did I put that "Community Server" category tag?

Article written by

A long time developer, I was an early adopter of Linux in the mid-90's for a few years until I entered corporate environments and worked with Microsoft technologies like ASP, then .NET. In 2008 I released Sueetie, an Online Community Platform built in .NET. In late 2012 I returned to my Linux roots and locked in on Java development. Much of my work is available on GitHub.