Example #1
0
        /// <summary>
        /// 获取主题列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖人</param>
        /// <param name="title">主题标题</param>
        /// <param name="type">主题类型</param>
        /// <param name="relativeID">相关ID</param>
        /// <param name="isLocked">是否锁定</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <returns>主题列表</returns>
        public static PagedList <ForumTopicEntity> AdminGetForumTopicList(Int32 pageIndex, String ftids, String username, String title, String type, String relativeID, String isLocked, String isHide, String startDate, String endDate)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = ForumTopicManager.AdminCountForumTopics(ftids, username, title, type, relativeID, isLocked, isHide, startDate, endDate);

            Byte     topictype = 0;
            Int32    rid = -1;
            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            if (!String.IsNullOrEmpty(relativeID) && !Int32.TryParse(relativeID, out rid))
            {
                throw new InvalidInputException("Relative ID is INVALID!");
            }

            return(ForumTopicRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount, ftids, username, title,
                                (!String.IsNullOrEmpty(type) && Byte.TryParse(type, out topictype) ? (ForumTopicType)topictype : new Nullable <ForumTopicType>()), rid,
                                (!String.IsNullOrEmpty(isLocked) ? "1".Equals(isLocked, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>()))
                   .ToPagedList(pageSize, recordCount));
        }
Example #2
0
        /// <summary>
        /// 获取主题总数(有缓存)
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <returns>主题总数</returns>
        private static Int32 CountForumTopics(String cid, String pid)
        {
            ForumTopicType type       = ForumTopicManager.GetForumTopicType(cid, pid);
            Int32          relativeID = ForumTopicManager.GetRelativeID(cid, pid);

            Int32 recordCount = ForumTopicCache.GetForumTopicCountCache(type, relativeID);//获取缓存

            if (recordCount < 0)
            {
                recordCount = ForumTopicRepository.Instance.CountEntities(type, relativeID, false);
                ForumTopicCache.SetForumTopicCountCache(type, relativeID, recordCount);//设置缓存
            }

            return(recordCount);
        }
Example #3
0
        /// <summary>
        /// 获取主题列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <returns>主题列表</returns>
        public static PagedList <ForumTopicEntity> GetForumTopicList(Int32 pageIndex, String cid, String pid)
        {
            ForumTopicType type       = ForumTopicManager.GetForumTopicType(cid, pid);
            Int32          relativeID = ForumTopicManager.GetRelativeID(cid, pid);

            if (type == ForumTopicType.Problem && !ProblemManager.InternalExistsProblem(relativeID))
            {
                throw new InvalidRequstException(RequestType.Problem);
            }
            else if (type == ForumTopicType.Contest && !ContestManager.InternalExistsContest(relativeID))
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            Int32 pageSize    = ForumTopicManager.FORUM_PAGE_SIZE;
            Int32 recordCount = ForumTopicManager.CountForumTopics(cid, pid);

            return(ForumTopicRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount, type, relativeID, false)
                   .ToPagedList(pageSize, recordCount));
        }
Example #4
0
        /// <summary>
        /// 创建树形列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="pid">题目ID</param>
        /// <returns>树形列表</returns>
        public static PagedList <TreeNode <ForumPostEntity> > GetPostTreeList(Int32 pageIndex, String pid)
        {
            PagedList <ForumTopicEntity> listTopic = ForumTopicManager.GetForumTopicList(pageIndex, String.Empty, pid);
            List <ForumPostEntity>       listPost  = ForumPostManager.GetForumPostList(listTopic, false);

            if (listPost == null || listPost.Count == 0)
            {
                return(PagedList <TreeNode <ForumPostEntity> > .Empty);
            }

            //将主题帖放入树节点数组
            List <TreeNode <ForumPostEntity> > listTreeNode = new List <TreeNode <ForumPostEntity> >();
            List <ForumPostEntity>             listRoot     = new List <ForumPostEntity>();

            //找出所有根节点
            for (Int32 i = 0; i < listPost.Count; i++)
            {
                if (listPost[i].Deepth == 0)
                {
                    listRoot.Add(listPost[i]);
                    listPost.RemoveAt(i--);
                }
            }

            //将Topic的Type和RelativeID写入Post中
            for (Int32 i = 0; i < listTopic.Count; i++)
            {
                for (Int32 j = 0; j < listRoot.Count; j++)
                {
                    if (listRoot[j].TopicID == listTopic[i].TopicID)
                    {
                        if (listTopic[i].Type != ForumTopicType.Default)
                        {
                            listRoot[j].RelativeType = listTopic[i].Type;
                            listRoot[j].RelativeID   = listTopic[i].RelativeID;
                        }

                        TreeNode <ForumPostEntity> node = new TreeNode <ForumPostEntity>(listRoot[j].PostID.ToString(), listRoot[j]);
                        listTreeNode.Add(node);
                        listRoot.RemoveAt(j);

                        break;
                    }
                }
            }

            //根据树节点数组创建树
            if (listTreeNode.Count > 0)
            {
                for (Int32 i = 0; i < listTreeNode.Count; i++)
                {
                    ForumPostManager.CreateTree(listTreeNode[i], listPost);
                }

                return(listTreeNode.ToPagedList(listTopic.PageSize, listTopic.RecordCount));
            }
            else
            {
                return(PagedList <TreeNode <ForumPostEntity> > .Empty);
            }
        }
Example #5
0
        /// <summary>
        /// 发布新主题
        /// </summary>
        /// <param name="topic">主题实体</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="content">主题帖内容</param>
        /// <param name="postip">发布者IP</param>
        /// <returns>是否成功发布</returns>
        public static Boolean InsertForumTopic(ForumTopicEntity topic, String cid, String pid, String content, String postip)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (String.IsNullOrEmpty(topic.Title))
            {
                throw new InvalidInputException("Topic title can not be NULL!");
            }

            if (topic.Title.Length > ForumPostRepository.TITLE_MAXLEN)
            {
                throw new InvalidInputException("Topic title is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(topic.Title))
            {
                throw new InvalidInputException("Topic title can not contain illegal keywords!");
            }

            if (String.IsNullOrEmpty(content) || content.Length < ForumPostRepository.POST_MINLEN)
            {
                throw new InvalidInputException("Topic content is too short!");
            }

            if (content.Length > ForumPostRepository.POST_MAXLEN)
            {
                throw new InvalidInputException("Topic content is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(content))
            {
                throw new InvalidInputException("Topic content can not contain illegal keywords!");
            }

            if (!UserSubmitStatus.CheckLastSubmitForumPostTime(UserManager.CurrentUserName))
            {
                throw new InvalidInputException(String.Format("You can not submit post more than twice in {0} seconds!", ConfigurationManager.SubmitInterval.ToString()));
            }

            topic.Type       = ForumTopicManager.GetForumTopicType(cid, pid);
            topic.RelativeID = (topic.Type == ForumTopicType.Default ? 0 : ForumTopicManager.GetRelativeID(cid, pid));

            if (topic.Type == ForumTopicType.Problem && !ProblemManager.InternalExistsProblem(topic.RelativeID))
            {
                throw new InvalidRequstException(RequestType.Problem);
            }
            else if (topic.Type == ForumTopicType.Contest && !ContestManager.InternalExistsContest(topic.RelativeID))
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            topic.UserName = UserManager.CurrentUserName;
            topic.LastDate = DateTime.Now;
            topic.Title    = HtmlEncoder.HtmlEncode(topic.Title);
            content        = HtmlEncoder.HtmlEncode(content);

            Boolean success = ForumTopicRepository.Instance.InsertEntity(topic, content, postip) > 0;

            if (success)
            {
                ForumTopicCache.IncreaseForumTopicCountCache(topic.Type, topic.RelativeID);//更新缓存

                if (topic.Type == ForumTopicType.Problem)
                {
                    ForumTopicCache.IncreaseForumTopicCountCache(ForumTopicType.Default, 0);//更新缓存
                }
            }

            return(success);
        }