# 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:

1. Get an instance of the comments service using the SystemManager's `GetCommentsService `method.
2. Get the comment that corresponds to the specified `comment Key`.\
   For more information see [Query comments](https://www.progress.com/documentation/sitefinity-cms/for-developers-query-comments).
3. Modify the comment.\
   After you get the comment, you modify it using the `UpdateComment`method 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

1. Get an instance of the comments service using the SystemManager's `GetCommentsService` method.
2. Get the comment that corresponds to the specified `comment Key`.\
   For more information see [Query comments](https://www.progress.com/documentation/sitefinity-cms/for-developers-query-comments).
3. To mark a comment as *Spam*, you set it's status to `StatusConstants.Spam`. Finally, you modify the comment using the `UpdateComment `method 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

1. Get an instance of the comments service by using the SystemManager's `GetCommentsService `method.
2. Get the comment that corresponds to the specified `comment Key`.\
   For more information see [Query comments](https://www.progress.com/documentation/sitefinity-cms/for-developers-query-comments).
3. Tn order to mark a comment as ham, you need you set it's status to *Published*.\
   You do this by setting the `Status`property to `StatusConstants.Published`. Finally, you modify the comment using the `UpdateComment `method 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);
          }
      }
   }

   ```
