Exemplo n.º 1
0
        public bool DeleteArchive(int archiveId)
        {
            IArchive archive = this.GetArchiveById(archiveId);

            if (archive == null)
            {
                return(false);
            }
            if (ArchiveFlag.GetFlag(archive.Get().Flags, BuiltInArchiveFlags.IsSystem))
            {
                throw new NotSupportedException("系统文档,不允许删除,请先取消系统设置后再进行删除!");
            }
            bool result = this._archiveRep.DeleteArchive(this.SiteId, archive.GetAggregaterootId());

            if (result)
            {
                //删除模板绑定
                this._tempRep.RemoveBind(archive.GetAggregaterootId(), TemplateBindType.ArchiveTemplate);


                //
                //TODO:删除评论及点评
                //

                //删除评论
                // new CommentDAL().DeleteArchiveComments(archiveID);

                //删除点评
                //new CommentBLL().DeleteArchiveReviews(archiveID);
            }

            archive = null;

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 文档页
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public string Archive(string tag, string id)
        {
            string   html = String.Empty;
            Archive  archive;
            Category category;

            archive = bll.Get(id);
            if (archive != null)
            {
                category = cbll.Get(a => a.ID == archive.Cid);

                if (category != null)
                {
                    const string pattern     = "^/[0-9a-zA-Z]+/[\\.0-9A-Za-z_-]+\\.html$";
                    const string pagePattern = "^/[\\.0-9A-Za-z_-]+\\.html$";

                    if (ArchiveFlag.GetFlag(archive.Flags, ArchiveInternalFlags.AsPage))
                    {
                        if (!Regex.IsMatch(Request.Path, pagePattern))
                        {
                            Response.StatusCode       = 301;
                            Response.RedirectLocation = String.Format("/{0}.html",
                                                                      String.IsNullOrEmpty(archive.Alias) ? archive.ID : archive.Alias
                                                                      );
                            Response.End();
                            return(null);
                        }
                    }
                    else if (!Regex.IsMatch(Request.Path, pattern) ||
                             (String.Compare(tag, category.Tag, true) != 0 || //如果分类tag不对,则301跳转
                              (!String.IsNullOrEmpty(archive.Alias) && String.Compare(id, archive.Alias, true) != 0)
                             ))                                               //设置了别名
                    {
                        Response.StatusCode       = 301;
                        Response.RedirectLocation = String.Format("/{0}/{1}.html",
                                                                  category.Tag,
                                                                  String.IsNullOrEmpty(archive.Alias) ? archive.ID : archive.Alias
                                                                  );
                        Response.End();
                        return(null);
                    }


                    //增加浏览次数
                    ++archive.ViewCount;
                    new System.Threading.Thread(() =>
                    {
                        try
                        {
                            bll.AddViewCount(archive.ID, 1);
                        }
                        catch
                        {
                        }
                    }).Start();

                    //显示页面
                    html = PageGenerator.Generate(PageGeneratorObject.ArchivePage, category, archive);
                    //再次处理模板
                    //html = PageUtility.Render(html, new { }, false);
                }
            }
            else
            {
                html = base.Render404();
            }
            return(html);
        }