Beispiel #1
0
        /// <summary>
        /// 详细页面地址
        /// </summary>
        /// <param name="itemId">推荐内容Id</param>
        /// <returns></returns>
        public string RecommendItemDetail(long itemId)
        {
            ContentItem contentItem = new ContentItemService().Get(itemId);

            if (contentItem == null)
            {
                return(string.Empty);
            }
            return(SiteUrls.Instance().ContentItemDetail(itemId));
        }
Beispiel #2
0
 /// <summary>
 /// 获取被评论对象名称
 /// </summary>
 /// <param name="commentedObjectId">被评论对象Id</param>
 /// <param name="tenantTypeId">租户类型Id</param>
 /// <returns></returns>
 public string GetCommentedObjectName(long commentedObjectId, string tenantTypeId)
 {
     if (tenantTypeId == TenantTypeIds.Instance().ContentItem())
     {
         ContentItem contentItem = new ContentItemService().Get(commentedObjectId);
         if (contentItem != null)
         {
             return(contentItem.Title);
         }
     }
     return(string.Empty);
 }
Beispiel #3
0
        /// <summary>
        /// 获取被评论对象(部分)
        /// </summary>
        /// <param name="commentedObjectId"></param>
        /// <returns></returns>
        public CommentedObject GetCommentedObject(long commentedObjectId)
        {
            ContentItem contentItem = new ContentItemService().Get(commentedObjectId);

            if (contentItem != null)
            {
                CommentedObject commentedObject = new CommentedObject();
                commentedObject.DetailUrl = SiteUrls.Instance().ContentItemDetail(commentedObjectId);
                commentedObject.Name      = contentItem.Title;
                commentedObject.Author    = contentItem.Author;
                commentedObject.UserId    = contentItem.UserId;
                return(commentedObject);
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// 资讯详细显示页
        /// </summary>
        public static string ContentItemDetail(this SiteUrls siteUrls, long contentItemId)
        {
            var contentItemService = new ContentItemService();
            var item = contentItemService.Get(contentItemId);

            if (item == null)
            {
                return(string.Empty);
            }
            if (item.ContentType != null && item.ContentType.ContentTypeKey == ContentTypeKeys.Instance().NewsLink())
            {
                return(item.AdditionalProperties.Get <string>("LinkUrl", string.Empty));
            }

            RouteValueDictionary routeValueDictionary = new RouteValueDictionary();

            routeValueDictionary.Add("contentItemId", contentItemId);

            return(CachedUrlHelper.Action("ContentItemDetail", "ChannelCms", CmsAreaName, routeValueDictionary));
        }
Beispiel #5
0
        /// <summary>
        /// 删除栏目
        /// </summary>
        /// <param name="contentFolder"></param>
        public void Delete(ContentFolder contentFolder)
        {
            if (contentFolder == null)
            {
                return;
            }

            //更新父栏目的ChildCount
            if (contentFolder.ParentId > 0)
            {
                ContentFolder parentContentFolder = Get(contentFolder.ParentId);
                if (parentContentFolder != null)
                {
                    parentContentFolder.ChildCount -= 1;
                    contentFolderRepository.Update(parentContentFolder);
                }
            }

            ContentItemService contentItemService = new ContentItemService();

            //所有后代栏目
            IEnumerable <ContentFolder> descendantContentFolders = GetDescendants(contentFolder.ContentFolderId);

            if (descendantContentFolders != null)
            {
                foreach (var item in descendantContentFolders)
                {
                    contentItemService.DeleteByFolder(item.ContentFolderId);
                    contentFolderRepository.Delete(item);
                }
            }
            contentFolderRepository.Delete(contentFolder);
            contentItemService.DeleteByFolder(contentFolder.ContentFolderId);
            EntityData.ForType(typeof(Navigation)).RealTimeCacheHelper.IncreaseAreaVersion("OwnerId", 0);

            //执行事件
            EventBus <ContentFolder> .Instance().OnAfter(contentFolder, new CommonEventArgs(EventOperationType.Instance().Delete(), ApplicationIds.Instance().CMS()));
        }
Beispiel #6
0
        /// <summary>
        /// 将EditModel转换成数据库实体
        /// </summary>
        public ContentItem AsContentItem(System.Web.HttpRequestBase Request)
        {
            ContentItem contentItem = null;

            if (this.ContentItemId > 0)
            {
                contentItem = new ContentItemService().Get(this.ContentItemId);
            }
            else
            {
                contentItem               = new ContentItem();
                contentItem.Author        = UserContext.CurrentUser == null ? "" : UserContext.CurrentUser.DisplayName;
                contentItem.IP            = WebUtility.GetIP();
                contentItem.UserId        = UserContext.CurrentUser == null ? 0 : UserContext.CurrentUser.UserId;
                contentItem.ContentTypeId = this.ContentTypeId;
            }

            if (this.ContentFolderId > 0)
            {
                ContentFolder folder = new ContentFolderService().Get(this.ContentFolderId);
                if (folder != null)
                {
                    contentItem.ContentFolderId = this.ContentFolderId;
                    if (this.AdditionalProperties == null)
                    {
                        this.AdditionalProperties = new Dictionary <string, object>();
                    }
                    IEnumerable <ContentTypeColumnDefinition> contentTypeColumnDefinitions = new MetadataService().GetColumnsByContentTypeId(this.ContentTypeId);
                    foreach (var item in contentTypeColumnDefinitions)
                    {
                        object value = null;


                        switch (item.DataType)
                        {
                        case "int":
                        case "long":
                            value = Request.Form.Get <long>(item.ColumnName, 0);
                            break;

                        case "datetime":
                            value = Request.Form.Get <DateTime>(item.ColumnName, DateTime.MinValue);
                            break;

                        case "bool":
                            value = Request.Form.Get <bool>(item.ColumnName, false);
                            break;

                        default:
                            value = Request.Form.Get <string>(item.ColumnName, string.Empty);
                            break;
                        }

                        if (this.AdditionalProperties.ContainsKey(item.ColumnName))
                        {
                            this.AdditionalProperties[item.ColumnName] = value;
                        }
                        else
                        {
                            this.AdditionalProperties.Add(item.ColumnName, value);
                        }
                    }
                }
            }
            contentItem.AdditionalProperties = this.AdditionalProperties;
            contentItem.IsEssential          = false;
            contentItem.IsLocked             = false;

            contentItem.IsGlobalSticky = this.IsGlobalSticky;
            if (this.GlobalStickyDate.CompareTo(DateTime.MinValue) > 0)
            {
                contentItem.GlobalStickyDate = this.GlobalStickyDate;
            }
            contentItem.IsFolderSticky = this.IsFolderSticky;
            if (this.FolderStickyDate.CompareTo(DateTime.MinValue) > 0)
            {
                contentItem.FolderStickyDate = this.FolderStickyDate;
            }
            contentItem.DisplayOrder = this.DisplayOrder;
            contentItem.FeaturedImageAttachmentId = this.FeaturedImageAttachmentId;
            contentItem.LastModified = DateTime.UtcNow;
            contentItem.Title        = this.Title;
            if (this.ReleaseDate.CompareTo(DateTime.MinValue) > 0)
            {
                contentItem.ReleaseDate = this.ReleaseDate.ToUniversalTime();
            }
            //摘要
            contentItem.Summary = this.Summary ?? string.Empty;
            if (this.TrimBodyAsSummary)
            {
                string summary = HtmlUtility.TrimHtml(Request.Form.Get <string>("Body", string.Empty), TextLengthSettings.TEXT_DESCRIPTION_MAXLENGTH);
                contentItem.Summary = summary;
            }

            if (contentItem.AdditionalProperties.ContainsKey("AutoPage"))
            {
                bool   autoPage   = Request.Form.Get <bool>("AutoPage", false);
                int    pageLength = Request.Form.Get <int>("PageLength", 1000);
                string body       = contentItem.AdditionalProperties.Get <string>("Body", string.Empty);
                if (autoPage)
                {
                    pageLength = pageLength > 0 ? pageLength : 1000;
                    if (!string.IsNullOrEmpty(body))
                    {
                        body = body.Replace(ContentPages.PageSeparator, "");
                        contentItem.AdditionalProperties["Body"] = string.Join(ContentPages.PageSeparator, ContentPages.GetPageContentForStorage(body, pageLength, true).ToArray());
                    }
                }
                else
                {
                    pageLength = 0;
                    body       = body.Replace(ContentPages.PageSeparator, "");
                    contentItem.AdditionalProperties["Body"]       = body;
                    contentItem.AdditionalProperties["pageLength"] = pageLength;
                }
            }

            if (contentItem.AdditionalProperties.ContainsKey("Editor"))
            {
                string editor = contentItem.AdditionalProperties.Get <string>("Editor", string.Empty);
                if (string.IsNullOrEmpty(editor))
                {
                    contentItem.AdditionalProperties["Editor"] = contentItem.ContentFolder.Editor;
                }
            }

            if (contentItem.FeaturedImageAttachmentId > 0)
            {
                AttachmentService <Attachment> attachmentService = new AttachmentService <Attachment>(TenantTypeIds.Instance().ContentItem());
                Attachment attachment = attachmentService.Get(contentItem.FeaturedImageAttachmentId);
                if (attachment != null)
                {
                    contentItem.FeaturedImage = attachment.GetRelativePath() + "\\" + attachment.FileName;
                }
                else
                {
                    contentItem.FeaturedImageAttachmentId = 0;
                }
            }
            else
            {
                contentItem.FeaturedImage = string.Empty;
            }
            return(contentItem);
        }
        /// <summary>
        /// 任务执行的内容
        /// </summary>
        /// <param name="taskDetail">任务配置状态信息</param>
        public void Execute(TaskDetail taskDetail)
        {
            ContentItemService contentItemService = new ContentItemService();

            contentItemService.ExpireStickyContentItems();
        }
Beispiel #8
0
        /// <summary>
        /// 删除用户在应用中的数据
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="takeOverUserName">用于接管删除用户时不能删除的内容(例如:用户创建的群组)</param>
        /// <param name="isTakeOver">是否接管被删除用户可被接管的内容</param>
        protected override void DeleteUser(long userId, string takeOverUserName, bool isTakeOver)
        {
            ContentItemService contentItemService = new ContentItemService();

            contentItemService.DeleteUser(userId, takeOverUserName, isTakeOver);
        }