Exemplo n.º 1
0
        public string SplitTopic(string jsonform)
        {
            var test = HttpUtility.UrlDecode(jsonform);

            System.Collections.Specialized.NameValueCollection formresult = HttpUtility.ParseQueryString(test);
            var replyIDs = new List <int>();

            foreach (string key in formresult.AllKeys)
            {
                if (key.EndsWith("cbxRow"))
                {
                    replyIDs.Add(Convert.ToInt32(formresult[key]));
                }
            }

            int    topicid = Convert.ToInt32(formresult["ctl00$splitTopicId"]);
            int    forumId = Convert.ToInt32(formresult["ctl00$ddlForum"]);
            string sort    = formresult["ctl00$ddlSort"];

            string subject = formresult["ctl00$tbxSubject"];

            if (String.IsNullOrEmpty(subject))
            {
                return("No subject supplied");
            }

            TopicInfo oldtopic = Topics.GetTopic(topicid);
            ForumInfo forum    = Forums.GetForum(forumId);

            if (replyIDs.Count == 0)
            {
                return("No replies selected");
            }
            int       lastreplyid = sort == "desc" ? replyIDs[replyIDs.Count - 1] : replyIDs[0];
            ReplyInfo lastreply   = Replies.GetReply(lastreplyid);

            //get the reply details
            var topic = new TopicInfo
            {
                Subject            = subject,
                Message            = lastreply.Message,
                Date               = lastreply.Date,
                UseSignatures      = lastreply.UseSignatures,
                IsSticky           = false,
                PosterIp           = lastreply.PosterIp,
                Views              = 0,
                ReplyCount         = replyIDs.Count - 1,
                Status             = (int)Enumerators.PostStatus.Open,
                UnModeratedReplies = 0,
                ForumId            = forumId,
                AuthorId           = lastreply.AuthorId,
                CatId              = forum.CatId
            };

            bool isModeratedForum = forum.ModerationLevel != (int)Enumerators.Moderation.UnModerated;

            if (isModeratedForum)
            {
                if (forum.ModerationLevel == (int)Enumerators.Moderation.AllPosts ||
                    forum.ModerationLevel == (int)Enumerators.Moderation.Topics)
                {
                    topic.Status = (int)Enumerators.PostStatus.UnModerated;
                }
            }

            int newtopicid = Topics.Add(topic);

            //delete the reply used as topic
            Replies.DeleteReply(lastreplyid);
            //move the other replies to this topic
            Replies.MoveReplies(newtopicid, replyIDs);
            //update the original topic count/dates
            Topics.Update(oldtopic.Id);

            Snitz.BLL.Admin.UpdateForumCounts();

            return("Selected replies were moved to a new topic");
        }