Work with groups

Create groups

To create a group:

  1. Get an instance of the Comment Service by using the GetCommentsService method part of the SystemManager.
  2. Create an AuthorProxy.
    When creating comments information is required about the author of the new comment, for example a name, an email, and so on. Therefore, there is an  AuthorProxy class that implements the IAuthor interface.
  3. To create a group, you need to create a GroupProxy. The constructor requires as parameters a title, description, and an author.
  4. Create the group using the CreateGroup method as part of the comment service by passing the groupProxy as a parameter.

The following code creates a group:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Sitefinity.Security.Claims;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Services.Comments;
using Telerik.Sitefinity.Services.Comments.Proxies;

namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Modules.Comments.Groups
{
    public partial class CommentsSnippets
    {
        public IGroup CreateGroupSnippet(string title, string description)
        {
            var cs = SystemManager.GetCommentsService();
            var author = new AuthorProxy(ClaimsManager.GetCurrentUserId().ToString());
            var groupProxy = new GroupProxy(title, description, author);
            var group = cs.CreateGroup(groupProxy);
            return group;
        }
    }
}

Query groups

Choose any of the following options to retrieve groups:

  • Get a thread by groupKey:

    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.Groups
    {
        public partial class GetGroup
        {
            public IGroup GetGroupSnippet(string groupKey)
            {
                var cs = SystemManager.GetCommentsService();
                return cs.GetGroup(groupKey);
            }
        }
    }
    
  • Get all groups by specific criteria.
    You must use the GetGroups method part of the comments service:

    C#
    using System.Collections.Generic;
    using Telerik.Sitefinity.Services;
    using Telerik.Sitefinity.Services.Comments;
    
    namespace SitefinityWebApp
    {
        public class GetGroup2
        {
            public IEnumerable<IGroup> GetGroupSnippet2(GroupFilter filter)
            {
                var cs = SystemManager.GetCommentsService().GetGroups(filter);
                return cs;
            }
        }
    }

    or

    C#
    using System.Collections.Generic;
    using Telerik.Sitefinity.Services;
    using Telerik.Sitefinity.Services.Comments;
    
    namespace SitefinityWebApp
    {
        public class GetGroup3
        {
            public IEnumerable<IGroup> GetGroupSnippet3(GroupFilter filter)
            {
                int totalCount = 0;
                
                ICommentService cs = SystemManager.GetCommentsService();
                IEnumerable<IGroup> gr = cs.GetGroups(filter, out totalCount);
                
                return gr;
            }
        }
    }

Delete groups

You can delete group using the DeleteGroup. ```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.Groups { public partial class CommentsSnippets { public void DeleteGroup(string groupKey) { var cs = SystemManager.GetCommentsService(); cs.DeleteGroup(groupKey); } } }

Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.