Beispiel #1
0
        public ForumTopicWrapperFull GetTopicPosts(int topicid)
        {
            //TODO: Deal with polls
            var postIds = ForumDataProvider.GetPostIDs(TenantId, topicid).Skip((int)_context.StartIndex);

            if (_context.Count > 0)
            {
                postIds = postIds.Take((int)_context.Count);
            }
            _context.SetDataPaginated();
            return(new ForumTopicWrapperFull(ForumDataProvider.GetTopicByID(TenantId, topicid).NotFoundIfNull(),
                                             ForumDataProvider.GetPostsByIDs(TenantId, postIds.ToList())));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _settings     = ForumManager.GetSettings(SettingsID);
            _forumManager = _settings.ForumManager;
            PostPageSize  = string.IsNullOrEmpty(Request["size"]) ? 20 : Convert.ToInt32(Request["size"]);

            if (Topic == null)
            {
                Response.Redirect(_settings.StartPageAbsolutePath);
            }

            if ((new Thread {
                ID = Topic.ThreadID
            }).Visible == false)
            {
                Response.Redirect(_settings.StartPageAbsolutePath);
            }


            int currentPageNumber = 0;

            if (!String.IsNullOrEmpty(Request["p"]))
            {
                try
                {
                    currentPageNumber = Convert.ToInt32(Request["p"]);
                }
                catch { currentPageNumber = 0; }
            }
            if (currentPageNumber <= 0)
            {
                currentPageNumber = 1;
            }

            int postCountInTopic;
            var posts = ForumDataProvider.GetPosts(TenantProvider.CurrentTenantID, Topic.ID, currentPageNumber, PostPageSize, out postCountInTopic);

            var postId = 0;

            if (!string.IsNullOrEmpty(Request["post"]))
            {
                try
                {
                    postId = Convert.ToInt32(Request["post"]);
                }
                catch { postId = 0; }
            }

            if (postId != 0)
            {
                var allposts = ForumDataProvider.GetPostIDs(TenantProvider.CurrentTenantID, Topic.ID);
                var idx      = -1;
                for (var j = 0; j < allposts.Count; j++)
                {
                    if (allposts[j] != postId)
                    {
                        continue;
                    }

                    idx = j;
                    break;
                }
                if (idx != -1)
                {
                    var page = idx / 20 + 1;
                    Response.Redirect("posts.aspx?t=" + Topic.ID + "&size=20&p=" + page + "#" + postId);
                }
            }

            PostPagesCount = postCountInTopic;
            var pageSize      = PostPageSize;
            var pageNavigator = new PageNavigator
            {
                PageUrl = string.Format(
                    CultureInfo.CurrentCulture,
                    "{0}?&t={1}&size={2}",
                    VirtualPathUtility.ToAbsolute("~/products/community/modules/forum/posts.aspx"),
                    Topic.ID,
                    pageSize
                    ),
                //_settings.LinkProvider.PostList(Topic.ID),
                CurrentPageNumber = currentPageNumber,
                EntryCountOnPage  = pageSize,
                VisiblePageCount  = 5,
                EntryCount        = postCountInTopic
            };


            bottomPageNavigatorHolder.Controls.Add(pageNavigator);

            var i = 0;

            foreach (var post in posts)
            {
                var postControl = (PostControl)LoadControl(_settings.UserControlsVirtualPath + "/PostControl.ascx");
                postControl.Post              = post;
                postControl.IsEven            = (i % 2 == 0);
                postControl.SettingsID        = SettingsID;
                postControl.CurrentPageNumber = currentPageNumber;
                postControl.PostsCount        = Topic.PostCount;
                postListHolder.Controls.Add(postControl);
                i++;
            }

            ForumDataProvider.SetTopicVisit(Topic);
            InitScripts();
            if (Topic.Type != TopicType.Poll)
            {
                return;
            }

            var q = ForumDataProvider.GetPollByID(TenantProvider.CurrentTenantID, Topic.QuestionID);

            if (q == null)
            {
                return;
            }

            var isVote = ForumDataProvider.IsUserVote(TenantProvider.CurrentTenantID, q.ID, SecurityContext.CurrentAccount.ID);

            var pollForm = new PollForm
            {
                VoteHandlerType  = typeof(PollVoteHandler),
                Answered         = isVote || Topic.Closed || !_forumManager.ValidateAccessSecurityAction(ForumAction.PollVote, q),
                Name             = q.Name,
                PollID           = q.ID.ToString(),
                Singleton        = (q.Type == QuestionType.OneAnswer),
                AdditionalParams = _settings.ID.ToString() + "," + q.ID.ToString()
            };


            foreach (var variant in q.AnswerVariants)
            {
                pollForm.AnswerVariants.Add(new PollForm.AnswerViarint
                {
                    ID        = variant.ID.ToString(),
                    Name      = variant.Name,
                    VoteCount = variant.AnswerCount
                });
            }


            pollHolder.Controls.Add(new Literal {
                Text = "<div style='position:relative; padding-left:20px; margin-bottom:15px;'>"
            });
            pollHolder.Controls.Add(pollForm);
            pollHolder.Controls.Add(new Literal {
                Text = "</div>"
            });
        }