Beispiel #1
0
        /// <summary>
        /// 更新主题锁定状态
        /// </summary>
        /// <param name="ids">主题ID列表</param>
        /// <param name="isLock">是否锁定</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateForumTopicIsLocked(String ids, Boolean isLocked)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                return(MethodResult.InvalidRequest(RequestType.ForumTopic));
            }

            Boolean success = ForumTopicRepository.Instance.UpdateEntityIsLocked(ids, isLocked) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No forum topic was {0}!", isLocked ? "locked" : "unlocked"));
            }

            ids.ForEachInIDs(',', id =>
            {
                ForumTopicCache.RemoveForumTopicCache(id);//删除缓存
            });

            return(MethodResult.SuccessAndLog("Admin {1} forum topic, id = {0}", ids, isLocked ? "lock" : "unlock"));
        }
Beispiel #2
0
        /// <summary>
        /// 根据ID得到一个对象实体
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <returns>对象实体</returns>
        public static ForumTopicEntity GetForumTopic(Int32 id)
        {
            if (id <= 0)
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            ForumTopicEntity topic = ForumTopicCache.GetForumTopicCache(id);

            if (topic == null)
            {
                topic = ForumTopicRepository.Instance.GetEntity(id);
                ForumTopicCache.SetForumTopicCache(topic);
            }

            if (topic == null)
            {
                throw new NullResponseException(RequestType.ForumTopic);
            }

            if (topic.IsHide && !AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException("You have no privilege to view the topic!");
            }

            return(topic);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }