コード例 #1
0
        private void UpdateArticle()
        {
            ArticleInfo objArticle = new ArticleInfo();

            objArticle.Id       = ArticleId;
            objArticle.PortalId = PortalId;

            //Normal
            objArticle.Title  = txtTitle.Text;
            objArticle.Author = txtAuthor.Text;
            objArticle.Source = txtSource.Text;
            objArticle.Quote  = chkQuote.Checked;
            objArticle.Draft  = chkDraft.Checked;

            objArticle.LinkUrl  = ctlLinkUrl.Url;
            objArticle.PinOrder = Convert.ToInt32(txtPinOrder.Text);
            //other
            if (ArticlePortalSettings.General.Portal_ArticleRequireApproval == true)
            {
                objArticle.Authed = chkAuthed.Checked;
            }
            else
            {
                objArticle.Authed = true;
            }
            objArticle.Featured = chkFeatured.Checked;
            objArticle.Active   = chkActive.Checked;

            objArticle.Thumbnail        = "";
            objArticle.Image            = UserInfo.IsInRole(PortalSettings.AdministratorRoleName)?ctlImage.Url : ctlUserImage.Url;
            objArticle.ImageDescription = txtImageDescription.Text;


            if (objArticle.Image.StartsWith("FileID="))
            {
                FileController fc = new FileController();
                DotNetNuke.Services.FileSystem.FileInfo      fi        = new DotNetNuke.Services.FileSystem.FileInfo();
                DotNetNuke.Entities.Portals.PortalController ctlPortal = new DotNetNuke.Entities.Portals.PortalController();
                DotNetNuke.Entities.Portals.PortalInfo       pi        = ctlPortal.GetPortal(PortalId);

                fi = GetFileInfoById(objArticle.Image);
                if (fi != null && System.IO.File.Exists(fi.PhysicalPath))
                {
                    objArticle.Thumbnail = DotNetNuke.Common.Globals.ApplicationPath + "/" + pi.HomeDirectory + "/" + fi.Folder + fi.FileName;
                    System.IO.FileInfo physicalFile = new System.IO.FileInfo(fi.PhysicalPath);

                    if (!fi.FileName.ToLower().StartsWith("thumb_"))                                                 //文件没有以"thumb_"开头,则先查找是否存在以thumb_ 开头的同名图片
                    {
                        if (System.IO.File.Exists(physicalFile.DirectoryName + "\\" + "thumb_" + physicalFile.Name)) //存在该文件,则自动指向
                        {
                            objArticle.Thumbnail = DotNetNuke.Common.Globals.ApplicationPath + "/" + pi.HomeDirectory + "/" + fi.Folder + "thumb_" + fi.FileName;
                        }
                        else//不存在,则生成该文件,然后指向
                        {
                            if (ArticlePortalSettings.General.Portal_ArticleGenerateThumb)
                            {
                                Utils.ResizeImage(fi.PhysicalPath, ArticlePortalSettings.General.Portal_ArticleThumbnailSize, physicalFile.DirectoryName + "\\" + "thumb_" + physicalFile.Name);
                                objArticle.Thumbnail = DotNetNuke.Common.Globals.ApplicationPath + "/" + pi.HomeDirectory + "/" + fi.Folder + "thumb_" + fi.FileName;
                            }
                        }
                    }
                }
            }
            //Add Categories
            objArticle.Categories = RecursiveHelper.GetAspNetTreeCheckList(tvCategory);

            //Add Tags
            objArticle.Tags = "";
            TagInfo    objTag  = new TagInfo();
            List <int> tagList = new List <int>();

            if (txtTag1.Text.Trim() != "")
            {
                objTag = TagController.GetByTag(txtTag1.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag1.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag2.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 1)
            {
                objTag = TagController.GetByTag(txtTag2.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag2.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag3.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 2)
            {
                objTag = TagController.GetByTag(txtTag3.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag3.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag4.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 3)
            {
                objTag = TagController.GetByTag(txtTag4.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag4.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag5.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 4)
            {
                objTag = TagController.GetByTag(txtTag5.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag5.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag6.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 5)
            {
                objTag = TagController.GetByTag(txtTag6.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag6.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag7.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 6)
            {
                objTag = TagController.GetByTag(txtTag7.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag7.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag8.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 7)
            {
                objTag = TagController.GetByTag(txtTag8.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag8.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag9.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 8)
            {
                objTag = TagController.GetByTag(txtTag9.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag9.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag10.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 9)
            {
                objTag = TagController.GetByTag(txtTag10.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag10.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            var newTaglist = (from p in tagList select p).Distinct();//remove the  repeated tag item.

            foreach (int item in newTaglist)
            {
                objArticle.Tags += item.ToString() + ",";
            }
            objArticle.Tags = Utils.RemoveSeperator(objArticle.Tags, ",");
            //Tags end

            //date
            if ((txtPublishDate.Text != null) && (txtPublishDate.Text != ""))
            {
                objArticle.PublishDate = Convert.ToDateTime(txtPublishDate.Text);
            }
            else
            {
                objArticle.PublishDate = DateTime.Now;
            }
            if (txtExpireDate.Text != "")
            {
                objArticle.ExpireDate = Convert.ToDateTime(txtExpireDate.Text);
            }

            objArticle.ViewRoles = Utils.GetCheckedItems(cblViewRoles, PortalSettings.AdministratorRoleId);
            //Rating
            objArticle.AllowRating = chkAllowRating.Checked;
            objArticle.RatingRoles = Utils.GetCheckedItems(cblRatingRoles, PortalSettings.AdministratorRoleId);

            //Recommend
            objArticle.AllowRecommend = chkAllowRecommend.Checked;
            objArticle.RecommendRoles = Utils.GetCheckedItems(cblRecommendRoles, PortalSettings.AdministratorRoleId);


            //Comment
            objArticle.AllowComment    = chkAllowComment.Checked;
            objArticle.CommentRoles    = Utils.GetCheckedItems(cblCommentRoles, PortalSettings.AdministratorRoleId);
            objArticle.AutoAuthComment = chkAutoAuthComment.Checked;
            //Download roles
            objArticle.DownloadRoles = Utils.GetCheckedItems(cblDownloadRoles, PortalSettings.AdministratorRoleId);

            objArticle.Summary = LocalUtils.RemoveAllHtmlTags(txtSummary.Text);
            objArticle.Article = txtDetail.Text;
            objArticle.UserId  = UserId;
            //Now processing attachment
            int newArticleId = -1;

            if (ArticleId == -1)
            {
                newArticleId = ArticleController.Add(objArticle);
            }
            else
            {
                ArticleController.Update(objArticle);
                newArticleId = ArticleId;
                AttachmentController.DeleteByArticle(ArticleId); //delete attachment first.
            }
            AttachmentInfo ai = new AttachmentInfo();

            foreach (AttachmentInfo item in AttachmentList)
            {
                ai.ArticleId = newArticleId;
                ai.FilePath  = item.FilePath;
                AttachmentController.Add(ai);
            }
            //Reset all
            ArticleId               = -1;
            AttachmentList          = new List <AttachmentInfo>();
            gvAttachment.DataSource = AttachmentList;
            gvAttachment.DataBind();
        }