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()
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?