Ejemplo n.º 1
0
        /// <summary>
        /// 资讯详情页
        /// </summary>
        public ActionResult ContentItemDetail(long contentItemId)
        {
            ContentItem contentItem = contentItemService.Get(contentItemId);

            if (contentItem == null || contentItem.User == null)
            {
                return(HttpNotFound());
            }

            //验证是否通过审核
            long currentSpaceUserId = UserIdToUserNameDictionary.GetUserId(contentItem.User.UserName);

            if (!authorizer.IsAdministrator(CmsConfig.Instance().ApplicationId) && contentItem.UserId != currentSpaceUserId &&
                (int)contentItem.AuditStatus < (int)(new AuditService().GetPubliclyAuditStatus(CmsConfig.Instance().ApplicationId)))
            {
                return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel
                {
                    Title = "尚未通过审核",
                    Body = "由于当前资讯尚未通过审核,您无法浏览当前内容。",
                    StatusMessageType = StatusMessageType.Hint
                })));
            }

            AttachmentService <Attachment> attachmentService = new AttachmentService <Attachment>(TenantTypeIds.Instance().ContentItem());


            //更新浏览计数
            CountService countService = new CountService(TenantTypeIds.Instance().ContentItem());

            countService.ChangeCount(CountTypes.Instance().HitTimes(), contentItem.ContentItemId, contentItem.UserId, 1, true);
            if (UserContext.CurrentUser != null)
            {
                //创建访客记录
                VisitService visitService = new VisitService(TenantTypeIds.Instance().ContentItem());
                visitService.CreateVisit(UserContext.CurrentUser.UserId, UserContext.CurrentUser.DisplayName, contentItem.ContentItemId, contentItem.Title);
            }
            //设置SEO信息
            pageResourceManager.InsertTitlePart(contentItem.Title);
            List <string> keywords = new List <string>();

            keywords.AddRange(contentItem.TagNames);
            string keyword = string.Join(" ", keywords.Distinct());

            keyword += " " + string.Join(" ", ClauseScrubber.TitleToKeywords(contentItem.Title));
            pageResourceManager.SetMetaOfKeywords(keyword);
            pageResourceManager.SetMetaOfDescription(contentItem.Summary);
            return(View(contentItem));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 转换成BlogThread类型
        /// </summary>
        /// <returns>文章实体</returns>
        public BlogThread AsBlogThread()
        {
            BlogThread blogThread = null;

            //写文章
            if (this.ThreadId <= 0)
            {
                blogThread        = BlogThread.New();
                blogThread.UserId = UserContext.CurrentUser.UserId;
                blogThread.Author = UserContext.CurrentUser.DisplayName;
                if (this.OwnerId.HasValue)
                {
                    blogThread.OwnerId      = this.OwnerId.Value;
                    blogThread.TenantTypeId = TenantTypeIds.Instance().Group();
                }
                else
                {
                    blogThread.OwnerId      = UserContext.CurrentUser.UserId;
                    blogThread.TenantTypeId = TenantTypeIds.Instance().User();
                }
                blogThread.OriginalAuthorId = UserContext.CurrentUser.UserId;
                blogThread.IsDraft          = this.IsDraft;
            }
            //编辑文章
            else
            {
                BlogService blogService = new BlogService();
                blogThread = blogService.Get(this.ThreadId);
                blogThread.LastModified = DateTime.UtcNow;
            }

            blogThread.Subject       = this.Subject;
            blogThread.Body          = this.Body;
            blogThread.IsSticky      = this.IsSticky;
            blogThread.IsLocked      = this.IsLocked;
            blogThread.PrivacyStatus = this.PrivacyStatus;
            blogThread.Keywords      = this.Keywords;
            if (string.IsNullOrEmpty(blogThread.Keywords))
            {
                string[] keywords = ClauseScrubber.TitleToKeywords(this.Subject);
                if (keywords.Length > 0)
                {
                    blogThread.Keywords = string.Join(" ", keywords);
                }
                else
                {
                    blogThread.Keywords = string.Empty;
                }
            }
            blogThread.Summary = this.Summary;
            if (string.IsNullOrEmpty(this.Summary))
            {
                blogThread.Summary = HtmlUtility.TrimHtml(this.Body, 100);
            }

            blogThread.FeaturedImageAttachmentId = this.FeaturedImageAttachmentId;
            if (blogThread.FeaturedImageAttachmentId > 0)
            {
                Attachment attachment = attachmentService.Get(blogThread.FeaturedImageAttachmentId);
                if (attachment != null)
                {
                    blogThread.FeaturedImage = attachment.GetRelativePath() + "\\" + attachment.FileName;
                }
                else
                {
                    blogThread.FeaturedImageAttachmentId = 0;
                }
            }
            else
            {
                blogThread.FeaturedImage = string.Empty;
            }

            return(blogThread);
        }