Article Likes

The ILikeableContentType interface provides support for liking content.

Why should I make my content likable?

If you would like users to provide feedback by demonstrating that they like your content then consider implementing the ILikeableContentType within your IContentType plugin.

Creating an ILikeableContentType plugin

The ILikeableContentType is defined in the Telligent.Evolution.Extensibility.Content.Version1 namespace of Telligent.Evolution.Core.dll.

It is important to note that one or more Core Services can be implemented in the same IContentType class.

Begin by defining whether a user can like your content. In this sample we limit liking to users that are not the author of the content. It is also a good practice to verify the content exist.

Similarly it is required to define who can unlike content. This logic can be similar to the CanLike method.

The SupportsLikes member returns whether any content of this content type can be liked. This property can simply return true.

public bool CanLike(Guid contentId, int userId)
{
    var content = LinksData.GetLink(contentId) as IContent;
    if (content == null) return false;

    return content.CreatedByUserId != userId;
}

public bool CanUnlike(Guid contentId, int userId)
{
    var content = LinksData.GetLink(contentId) as IContent;
    if (content == null) return false;

    return content.CreatedByUserId != userId;
}

public bool SupportsLikes
{
    get { return true; }
}

Here is the full sample.

using System;
using System.Collections.Generic;
using System.Linq;
using Telligent.Evolution.Extensibility;
using Telligent.Evolution.Extensibility.Api.Entities.Version1;
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, ILikeableContentType
    {
        IContentStateChanges _contentState = null;

        #region IPlugin Members

        public string Description
        {
            get { return "Items in a Links collection"; }
        }

        public void Initialize()
        {
        
        }

        public string Name
        {
            get { return "Link Items"; }
        }
        
        #endregion

        #region IContentType Members

        public Guid[] ApplicationTypes
        {
            get { return new Guid[] { ContentTypes.LinksApplicationId }; }
        }

        public void AttachChangeEvents(IContentStateChanges stateChanges)
        {
            _contentState = stateChanges;
        }

        public Guid ContentTypeId
        {
            get { return ContentTypes.LinksItemId; }
        }

        public string ContentTypeName
        {
            get { return "Links Item"; }
        }

        public IContent Get(Guid contentId)
        {
            return LinksData.GetLink(contentId);
        }

        #endregion

        #region ILikeableContentType

        public bool CanLike(Guid contentId, int userId)
        {
            var content = LinksData.GetLink(contentId) as IContent;
            if (content == null) return false;

            return content.CreatedByUserId != userId;
        }

        public bool CanUnlike(Guid contentId, int userId)
        {
            var content = LinksData.GetLink(contentId) as IContent;
            if (content == null) return false;

            return content.CreatedByUserId != userId;
        }

        public bool SupportsLikes
        {
            get { return true; }
        }

        #endregion
    }
}