Esempio n. 1
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);
        }
Esempio n. 2
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));
        }
Esempio n. 3
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);
        }