Modify comments
Sitefinity CMS enables you to modify a comment through the Comments API.
Modify comment by comment key
To modify a comment, for example a comment for a News item, perform the following:
-
Get an instance of the comments service using the SystemManager's
GetCommentsServicemethod. -
Get the comment that corresponds to the specified
comment Key.
For more information see Query comments. -
Modify the comment.
After you get the comment, you modify it using theUpdateCommentmethod of the comments service.Consider the code sample below:
C#using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Telerik.Sitefinity.Services; namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.Comments { public partial class CommentsSnippets { public static void ModifyCommentByCommentKey(string commentKey, string newMessage) { //gets an instance of the comment service var cs = SystemManager.GetCommentsService(); //gets a comment by comment key var comment = cs.GetComment(commentKey); //updates the message of the comment if (comment != null) { comment.Message = newMessage; cs.UpdateComment(comment); } } } }
Mark the status of a comment as Spam
-
Get an instance of the comments service using the SystemManager's
GetCommentsServicemethod. -
Get the comment that corresponds to the specified
comment Key.
For more information see Query comments. -
To mark a comment as Spam, you set it's status to
StatusConstants.Spam. Finally, you modify the comment using theUpdateCommentmethod of the comments service.
Consider the code sample below:C#using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Telerik.Sitefinity.Services; using Telerik.Sitefinity.Services.Comments; namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.Comments { public partial class CommentsSnippets { public static void ModifyCommentMarkAsSpam(string commentKey) { //gets an instance of the comments service var cs = SystemManager.GetCommentsService(); //gets comment by comment key var comment = cs.GetComment(commentKey); //updates the status to Spam comment.Status = StatusConstants.Spam; cs.UpdateComment(comment); } } }
Mark the status of a comment as Published
- Get an instance of the comments service by using the SystemManager's
GetCommentsServicemethod. - Get the comment that corresponds to the specified
comment Key.
For more information see Query comments. - Tn order to mark a comment as ham, you need you set it's status to Published.
You do this by setting theStatusproperty toStatusConstants.Published. Finally, you modify the comment using theUpdateCommentmethod of the comments service.
Consider the code sample below:C#using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Telerik.Sitefinity.Services; using Telerik.Sitefinity.Services.Comments; namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.Comments { public partial class CommentsSnippets { public static void ModifyCommentMarkAsPublished(string commentKey) { //gets an instance of the comments service var cs = SystemManager.GetCommentsService(); //gets comment by comment key var comment = cs.GetComment(commentKey); //updates the status to Published comment.Status = StatusConstants.Published; cs.UpdateComment(comment); } } }