IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
Sitefinity CMS allows you to modify a comment through the Comments API.
When modifying a news comment, you must perform the following:
Get the news item.
First, get an instance of the master version of the news item that corresponds to the specified ID.
For more information about finding specific news items, see For developers: Query news items.
Get the live version.
The instance that corresponds to the ID argument is the master version of the news item. You can get the live version explicitly.
Get the comment.
Get the comment that corresponds to the specified ID.
Modify the comment.
After you get the comment, you modify it.
Save the changes.
Finally, you save all changes.
The following examples modify a news comment by its ID.
Native API
public
void
ModifyCommentByIdNativeAPI(Guid masterNewsId, Guid commentId,
string
newContent)
{
NewsManager newsManager = NewsManager.GetManager();
// Check whether the news item exists
NewsItem news = newsManager.GetNewsItems().Where(nI => nI.Id == masterNewsId).FirstOrDefault();
if
(news !=
null
)
news = newsManager.Lifecycle.GetLive(news)
as
NewsItem;
// Get the comment
Comment comment = newsManager.GetComments().Where(c => c.CommentedItemID == news.Id && c.Id == commentId).SingleOrDefault();
(comment !=
// Modify the comment
comment.Content = newContent;
// Save the changes
newsManager.SaveChanges();
}
First, you get an instance of the NewsManager class. You get the specified news item by querying all items and filtering the collection by the ID property.
If the item exists, you get its live version. Then, you get the comment by calling GetComments and filtering based on theCommentedItemID and Id properties. Then, you modify the content of the comment with newContent. Finally, you save the changes.
ModifyCommentByIdFluentAPI(Guid masterNewsId, Guid commentId,
int
newsCount = 0;
App.WorkWith().NewsItems().Where(nI => nI.Id == masterNewsId).Count(
out
newsCount);
(newsCount > 0)
var liveNewsItem = App.WorkWith().NewsItem(masterNewsId).GetLive();
(liveNewsItem !=
commentCount = 0;
// Check whether the comment exists
liveNewsItem.Comments().Where(c => c.Id == commentId).Count(
commentCount);
(commentCount > 0)
liveNewsItem.Comment(commentId).Do(c =>
c.Content = newContent;
}).SaveChanges();
First, you use the plural facade of the news item to assure that the item with the specified Id exists.
Then, you use the GetLive method of the singular facade to get the instance of the live version. You initialize the plural facade of the comments by calling Comments. Then, you get the comment by filtering based on the Id property. You modify the content of the comment with newContent. Finally, you save the changes.
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important