Esempio n. 1
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 });
        }
Esempio n. 2
0
        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 });
        }
Esempio n. 3
0
 /// <summary>
 /// 向缓存中写入指定帖子信息
 /// </summary>
 /// <param name="Post">指定帖子信息</param>
 public static void SetForumPostCache(ForumPostEntity post)
 {
     if (post != null) CacheManager.Set(GetForumPostCacheKey(post.PostID), post);
 }
Esempio n. 4
0
        /// <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;
        }