/// <summary>
 /// 向缓存中写入指定主题信息
 /// </summary>
 /// <param name="topic">指定主题信息</param>
 public static void SetForumTopicCache(ForumTopicEntity topic)
 {
     if (topic != null)
     {
         CacheManager.Set(GetForumTopicCacheKey(topic.TopicID), topic);
     }
 }
        public ActionResult Reply(Int32 id, FormCollection form)
        {
            ForumPostEntity  post  = ForumPostManager.GetForumPost(id);
            ForumTopicEntity topic = ForumTopicManager.GetForumTopic(post.TopicID);

            if (topic.Type == ForumTopicType.Contest)
            {
                return(RedirectToErrorMessagePage("This topic is not in the main disscus board!"));
            }

            ForumPostEntity reply = new ForumPostEntity()
            {
                Title   = form["title"],
                Content = form["content"]
            };

            String userip = this.GetCurrentUserIP();
            String link   = Url.Action("Reply", "Forum", new { id = post.PostID });

            if (!ForumPostManager.InsertForumPost(reply, topic, post, userip, link))
            {
                return(RedirectToErrorMessagePage("Failed to post your reply!"));
            }

            return(RedirectToAction("Reply", "Forum", new { id = post.PostID }));
        }
Exemple #3
0
        public ActionResult Reply(String id, FormCollection form)
        {
            ContestEntity    contest = ViewData["Contest"] as ContestEntity;
            ForumPostEntity  post    = ForumPostManager.GetForumPostByTopicID(id);
            ForumTopicEntity topic   = ForumTopicManager.GetForumTopic(post.TopicID);

            if (topic.Type != ForumTopicType.Contest || topic.RelativeID != contest.ContestID)
            {
                return(RedirectToErrorMessagePage("This contest does not have this topic!"));
            }

            ForumPostEntity reply = new ForumPostEntity()
            {
                Title   = form["title"],
                Content = form["content"]
            };

            String userip = this.GetCurrentUserIP();
            String link   = Url.Action("Topic", "Forum", new { area = "Contest", cid = contest.ContestID, id = post.TopicID });

            if (!ForumPostManager.InsertForumPost(reply, topic, post, userip, link))
            {
                return(RedirectToErrorMessagePage("Failed to post your reply!"));
            }

            return(RedirectToAction("Topic", "Forum", new { area = "Contest", cid = contest.ContestID, id = post.TopicID }));
        }
Exemple #4
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);
        }
        /// <summary>
        /// 获取帖子列表
        /// </summary>
        /// <param name="topic">主题实体</param>
        /// <param name="includeHide">是否包含隐藏主题</param>
        /// <returns>帖子列表</returns>
        public static List <ForumPostEntity> GetForumPostList(ForumTopicEntity topic, Boolean includeHide)
        {
            List <ForumTopicEntity> topics = new List <ForumTopicEntity>()
            {
                topic
            };

            return(GetForumPostList(topics, includeHide));
        }
Exemple #6
0
        /// <summary>
        /// 讨论版主题页面
        /// </summary>
        /// <param name="id">主题ID</param>
        /// <returns>操作后的结果</returns>
        public ActionResult Topic(Int32 id = -1)
        {
            ContestEntity    contest = ViewData["Contest"] as ContestEntity;
            ForumPostEntity  post    = ForumPostManager.GetForumPostByTopicID(id.ToString());
            ForumTopicEntity topic   = ForumTopicManager.GetForumTopic(post.TopicID);

            if (topic.Type != ForumTopicType.Contest || topic.RelativeID != contest.ContestID)
            {
                return(RedirectToErrorMessagePage("This contest does not have this topic!"));
            }

            List <ForumPostEntity> list = ForumPostManager.GetForumPostList(topic, false);

            return(View(new Tuple <ForumTopicEntity, List <ForumPostEntity> >(topic, list)));
        }
Exemple #7
0
        public ActionResult New(FormCollection form)
        {
            ContestEntity    contest = ViewData["Contest"] as ContestEntity;
            ForumTopicEntity topic   = new ForumTopicEntity()
            {
                Title = form["title"],
            };

            String userip = this.GetCurrentUserIP();

            if (!ForumTopicManager.InsertForumTopic(topic, contest.ContestID.ToString(), String.Empty, form["content"], userip))
            {
                return(RedirectToErrorMessagePage("Failed to post your topic!"));
            }

            return(RedirectToAction("List", "Forum", new { area = "Contest", cid = contest.ContestID }));
        }
        /// <summary>
        /// 讨论版回复页面
        /// </summary>
        /// <param name="id">帖子ID</param>
        /// <param name="tid">主题ID</param>
        /// <returns>操作后的结果</returns>
        public ActionResult Reply(Int32 id = -1, String tid = "")
        {
            ForumPostEntity  post  = (String.IsNullOrEmpty(tid) ? ForumPostManager.GetForumPost(id) : ForumPostManager.GetForumPostByTopicID(tid));
            ForumTopicEntity topic = ForumTopicManager.GetForumTopic(post.TopicID);

            if (topic.Type == ForumTopicType.Contest)
            {
                return(RedirectToErrorMessagePage("This topic is not in the main disscus board!"));
            }

            post.RelativeType = (topic.Type == ForumTopicType.Problem ? topic.Type : ForumTopicType.Default);
            post.RelativeID   = (topic.Type == ForumTopicType.Problem ? topic.RelativeID : -1);

            List <TreeNode <ForumPostEntity> > listTreeNode = ForumPostManager.GetPostTreeList(topic, post.PostID);

            ViewBag.IsLocked = topic.IsLocked;

            return(View(new Tuple <ForumPostEntity, List <TreeNode <ForumPostEntity> > >(post, listTreeNode)));
        }
        /// <summary>
        /// 创建树形列表
        /// </summary>
        /// <param name="topic">主题帖</param>
        /// <param name="postID">帖子ID</param>
        /// <returns>树形列表</returns>
        public static List <TreeNode <ForumPostEntity> > GetPostTreeList(ForumTopicEntity topic, Int32 postID)
        {
            List <ForumPostEntity> listPost = ForumPostManager.GetForumPostList(topic, false);

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

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

            //将父节点是帖子ID的节点放入树节点数组
            for (Int32 i = 0; i < listPost.Count; i++)
            {
                if (listPost[i].ParentPostID == postID)
                {
                    TreeNode <ForumPostEntity> node = new TreeNode <ForumPostEntity>(listPost[i].PostID.ToString(), listPost[i]);
                    listTreeNode.Add(node);
                    listPost.RemoveAt(i--);
                }
            }

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

                return(listTreeNode);
            }
            else
            {
                return(new List <TreeNode <ForumPostEntity> >());
            }
        }
Exemple #10
0
        public ActionResult New(FormCollection form)
        {
            ForumTopicEntity topic = new ForumTopicEntity()
            {
                Title = form["title"]
            };

            String pid    = form["pid"];
            String userip = this.GetCurrentUserIP();

            if (!ForumTopicManager.InsertForumTopic(topic, String.Empty, pid, form["content"], userip))
            {
                return(RedirectToErrorMessagePage("Failed to post your topic!"));
            }

            if (String.IsNullOrEmpty(pid))
            {
                return(RedirectToAction("Main", "Forum"));
            }
            else
            {
                return(RedirectToAction("Problem", "Forum", new { pid = pid }));
            }
        }
        /// <summary>
        /// 增加一条回帖
        /// </summary>
        /// <param name="post">帖子实体</param>
        /// <param name="topic">主题实体</param>
        /// <param name="parentPost">回复的帖子实体</param>
        /// <param name="postip">发布者IP</param>
        /// <param name="link">当前页面地址</param>
        /// <returns>是否成功增加</returns>
        public static Boolean InsertForumPost(ForumPostEntity post, ForumTopicEntity topic, ForumPostEntity parentPost, String postip, String link)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

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

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

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

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

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

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

            if (parentPost.Deepth + 1 < ForumPostRepository.DEEPTH_MIN)
            {
                throw new InvalidInputException("Reply deepth is INVALID!");
            }

            if (parentPost.Deepth + 1 > ForumPostRepository.DEEPTH_MAX)
            {
                throw new InvalidInputException("Reply deepth is too deep!");
            }

            if (topic.IsLocked)
            {
                throw new NoPermissionException("You have no privilege to reply the post!");
            }

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

            post.TopicID      = parentPost.TopicID;
            post.Title        = HtmlEncoder.HtmlEncode(post.Title);
            post.Content      = HtmlEncoder.HtmlEncode(post.Content);
            post.UserName     = UserManager.CurrentUserName;
            post.Deepth       = parentPost.Deepth + 1;
            post.ParentPostID = parentPost.PostID;
            post.PostDate     = DateTime.Now;
            post.PostIP       = postip;

            Boolean success = ForumPostRepository.Instance.InsertEntity(post) > 0;

            if (success && !String.Equals(parentPost.UserName, post.UserName))
            {
                if (ConfigurationManager.ReplyPostMailNotification)
                {
                    try
                    {
                        UserMailEntity mail = new UserMailEntity();
                        String         url  = ConfigurationManager.DomainUrl + ((link[0] == '/') ? link.Substring(1) : link);

                        mail.FromUserName = ConfigurationManager.SystemAccount;
                        mail.ToUserName   = parentPost.UserName;
                        mail.Title        = "Your post has new reply!";
                        mail.Content      =
                            String.Format("Your post \"{0}\" has new reply, <br/>", parentPost.Title) +
                            String.Format("Please visit <a href=\"{0}\" target=\"_blank\">{0}</a>", url);

                        UserMailManager.InternalSendUserMail(mail);
                    }
                    catch { }
                }
            }

            return(success);
        }
Exemple #12
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);
        }