Comment service

The CommentService class is one of the service classes available. The CommentService class provides functionality for handling commenting on all content types. With the CommentService class, you can perform actions like Insert, Get and Search. When searching for comments, you use the CommentQuery class along with CommentService.Search(); The CommentQuery class is much like the ContentQuery class where you can set properties like ContentID, ContentTypes, Depth and OrderBy.

Examples

Example 1. Add a comment to a content type

var comment = new Comment();

comment.Title = "A comment title"; 
comment.Body = "My comment text";
comment.LanguageID = Content.LanguageID;
comment.ContentID = Content.ID;

CommentService.Insert(comment);

 

Example 2. Get the five latest comments from all content types on the web site.

var query = new CommentQuery();
query.LanguageID = null;
query.OrderBy.Add(new SortItem(CommentColumn.Created, SortDirection.Descending));
query.PageSize = 5;
var results = CommentService.Search(query);

 

Example 3. Get the 10 latest comments for the content with id 25

int contentID = 25;
int languageID = 3;
int pageIndex = 0;
int pageSize = 10;
int? totalItemCount = null;

var comments = CommentService.GetByContent(contentID, languageID, pageIndex, pageSize, totalItemCount);

 

Example 4. Get the 10 latest comments for all blogs on the web site

var query = new CommentQuery();
query.LanguageID = null;
query.OrderBy.Add(new SortItem(CommentColumn.Created, SortDirection.Descending));
query.PageSize = 10;
query.ContentTypes.Add(ContentTypeHelper.Get<Lemoon.ContentTypes.BlogEntry>());

var results = CommentService.Search(query);