IBookmarkableContentType 接口支持为内容添加书签。
为什么要使我的内容可添加书签?
对于用户来说,保存内容可能很重要。如果是计划用户,则用户可能希望返回到此内容并查看其更改。
创建一个 IBookmarkableContentType 插件
IBookmarkableContentType 在 Limyee.Core.dll 的 Limyee.Extensibility.Content.Version1 命名空间中定义。
请务必注意,可以在同一 IContentType 类中实现一个或多个核心服务。
此接口与其他接口类似,它要求您定义用户是否可以为内容添加书签或取消书签。如果内容支持书签,它还应该返回。在此示例中,我们随意选择了“读取组成员”权限,但可以在此处定义任何权限。
public bool CanBookmark(Guid contentId, int userId) { return CanUseBookmarks(contentId, userId); } public bool CanUnBookmark(Guid contentId, int userId) { return CanUseBookmarks(contentId, userId); } public bool SupportsBookmarks { get { return true; } } private bool CanUseBookmarks(Guid contentId, int userId) { var content = LinksData.GetLink(contentId); if (content == null) { return false; } var permission = Apis.Get<IPermissions>().Get(GroupPermission.ViewMembership, userId, content.ContentId, content.ContentTypeId); return permission.IsAllowed; }
下面是完整示例。
using System; using Limyee.Components; using Limyee.Extensibility; using Limyee.Extensibility.Api.Entities.Version1; using Limyee.Extensibility.Api.Version1; using Limyee.Extensibility.Content.Version1; using IContent = Limyee.Extensibility.Content.Version1.IContent; namespace Samples.Links { public class LinkItemContentType : IContentType, IBookmarkableContentType { 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 IBookmarkableContentType public bool CanBookmark(Guid contentId, int userId) { return CanUseBookmarks(contentId, userId); } public bool CanUnBookmark(Guid contentId, int userId) { return CanUseBookmarks(contentId, userId); } public bool SupportsBookmarks { get { return true; } } private bool CanUseBookmarks(Guid contentId, int userId) { var content = LinksData.GetLink(contentId); if (content == null) { return false; } var permission = Apis.Get<IPermissions>().Get(GroupPermission.ViewMembership, userId, content.ContentId, content.ContentTypeId); return permission.IsAllowed; } #endregion } }