<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Comments</title><link>https://community.telligent.com/community/11/w/developer-training/65103/comments</link><description /><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>Comments</title><link>https://community.telligent.com/community/11/w/developer-training/65103/comments</link><pubDate>Thu, 13 Jun 2019 19:28:32 GMT</pubDate><guid isPermaLink="false">bb3c263e-4f2c-48dd-9b9f-158a88cc1ac7</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65103/comments#comments</comments><description>Current Revision posted to Developer Training by Ben Tiedt on 06/13/2019 19:28:32&lt;br /&gt;
&lt;p&gt;The [[api-documentation:ICommentableContentType Plugin Type|ICommentableContentType]] interface enables comments to be created for your content type.&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h3&gt;&lt;a id="Why_should_I_support_comments" name="Why_should_I_support_comments"&gt;&lt;/a&gt;Why should I support comments?&lt;/h3&gt;
&lt;p&gt;When considering social features comments can be a great way to allow users to provide feedback. One example is if you were creating a shopping cart and wanted to allow comments on your products. In this sample comments can be added to links. This can be used as a way to allow users to add feedback on the content in the links.&lt;/p&gt;
&lt;h3&gt;&lt;a id="Creating_an_ICommentableContentType_plugin" name="Creating_an_ICommentableContentType_plugin"&gt;&lt;/a&gt;Creating an ICommentableContentType plugin&lt;/h3&gt;
&lt;p&gt;To add support for commenting implement the [[api-documentation:ICommentableContentType Plugin Type|ICommentableContentType]] interface that is defined in the &lt;code&gt;Telligent.Evolution.Extensibility.Content.Version1&lt;/code&gt; namespace of &lt;code&gt;Telligent.Evolution.Core.dll&lt;/code&gt;. &lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It is important to note that one or more Core Services can be implemented in the same [[api-documentation:IContentType Plugin Type|IContentType]] class.&lt;/p&gt;
&lt;p&gt;This sample further extends the [[api-documentation:IContentType Plugin Type|IContentType]] sample from the &lt;a href="/training/w/developer90/52446.creating-a-custom-application-content" target="_blank"&gt;Application/Content&lt;/a&gt; document.&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;using System;
using Telligent.Evolution.Extensibility;
using Telligent.Evolution.Extensibility.Api.Version1;
using Telligent.Evolution.Extensibility.Content.Version1;
using IContent = Telligent.Evolution.Extensibility.Content.Version1.IContent;

namespace Samples.Links
{
    public class LinkItemContentType : IContentType, ICommentableContentType
    {
        IContentStateChanges _contentState = null;

        #region IPlugin Members

        //...
        
        #endregion

        #region IContentType Members

        //...

        #endregion

        #region ICommentableContentType

        //...

        #endregion
    }
}
&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;After implementing the [[api-documentation:IPlugin Plugin Type|IPlugin]] and [[api-documentation:IContentType Plugin Type|IContentType]] interface, begin by defining if the user can comment with the &lt;code&gt;CanCreateComment&lt;/code&gt; method. You can do something as simple as checking if the user is logged in or you can use the permissions API to check if the user has a certain type of permission. For this sample we make sure the user is logged in and registered.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public bool CanCreateComment(Guid contentId, int userId)
{
    var content = LinksData.GetLink(contentId);
    if (content == null) return false;
    
    return !Apis.Get&amp;lt;IUsers&amp;gt;().Get(new UsersGetOptions{ Id = userId }).IsSystemAccount.GetValueOrDefault();
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Next you will want to check if the user has permission to delete a comment. This is similar to above but we added a check to see if the user accessing the comment is the author. Here we allow the user to delete their own comment.&lt;/p&gt;
&lt;p&gt;Editing a comment can be similar to deleting a comment. You can verify the accessing user is the same as the comment author.&lt;/p&gt;
&lt;p&gt;And unless you want to restrict viewing comments, the&amp;nbsp;&lt;code&gt;CanReadComment&lt;/code&gt; can simply return true.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public bool CanDeleteComment(Guid commentId, int userId)
{
    var comment = Apis.Get&amp;lt;IComments&amp;gt;().Get(commentId);
    if (comment == null) return false;

    return comment.UserId == userId;
}

public bool CanModifyComment(Guid commentId, int userId)
{
    var comment = Apis.Get&amp;lt;IComments&amp;gt;().Get(commentId);
    if (comment == null) return false;

    return comment.UserId == userId;
}

public bool CanReadComment(Guid commentId, int userId)
{
    return true;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here is the full sample.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://community.telligent.com/cfs-file/__key/communityserver-wikis-components-files/00-00-00-12-83/5417_2E00_LinkItemContentType_2E00_cs"&gt;community.telligent.com/.../5417_2E00_LinkItemContentType_2E00_cs&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>