Example #1
0
        public override void DataBind()
        {
            base.DataBind();

            if (Feed == null)
            {
                return;
            }

            newsText.Text = HtmlUtility.GetFull(Feed.Text);
            Date.Text     = Feed.Date.Ago();

            EditorButtons.Visible = CommunitySecurity.CheckPermissions(Feed, NewsConst.Action_Edit);

            if (EditorButtons.Visible)
            {
                EditorButtons.Text = string.Format(CultureInfo.CurrentCulture, "{0}{1}",
                                                   string.Format(CultureInfo.CurrentCulture, "<li><a class=\"dropdown-item\" href=\"{0}?docID={1}{3}\">{2}</a></li>", GetEditUrl(), Feed.Id, NewsResource.EditButton, UserIdAttribute),
                                                   string.Format(CultureInfo.CurrentCulture, "<li><a class=\"dropdown-item\" href=\"javascript:;\" onclick=\"javascript:if(window.confirm('{0}'))FeedView.Remove('{1}',callbackRemove);\">{2}</a></li>", NewsResource.ConfirmRemoveMessage, Feed.Id, NewsResource.DeleteButton));
            }

            profileLink.Text = CoreContext.UserManager.GetUsers(new Guid(Feed.Creator)).RenderCustomProfileLink("", "linkMedium");

            if (Feed is FeedPoll)
            {
                var poll       = (FeedPoll)Feed;
                var isMakeVote = TenantUtil.DateTimeNow() <= poll.EndDate && !poll.IsUserVote(SecurityContext.CurrentAccount.ID.ToString());

                var pollForm = new PollForm
                {
                    VoteHandlerType  = typeof(PollVoteHandler),
                    Answered         = !isMakeVote,
                    Name             = poll.Caption,
                    PollID           = poll.Id.ToString(CultureInfo.CurrentCulture),
                    Singleton        = (poll.PollType == FeedPollType.SimpleAnswer),
                    AdditionalParams = poll.Id.ToString(CultureInfo.CurrentCulture)
                };

                foreach (var variant in poll.Variants)
                {
                    pollForm.AnswerVariants.Add(new PollForm.AnswerViarint()
                    {
                        ID        = variant.ID.ToString(CultureInfo.CurrentCulture),
                        Name      = variant.Name,
                        VoteCount = poll.GetVariantVoteCount(variant.ID)
                    });
                }
                pollHolder.Controls.Add(pollForm);
            }
            else
            {
                pollHolder.Visible = false;
                newsText.Visible   = true;
            }
        }
Example #2
0
        public override void DataBind()
        {
            base.DataBind();

            if (Feed != null)
            {
                newsText.Text = HtmlUtility.GetFull(Feed.Text, ASC.Web.Community.Product.CommunityProduct.ID);
                Date.Text     = Feed.Date.Ago();

                EditorButtons.Visible = CommunitySecurity.CheckPermissions(Feed, NewsConst.Action_Edit);
                if (EditorButtons.Visible)
                {
                    EditorButtons.Text = string.Format(CultureInfo.CurrentCulture, "{0}<span class='splitter'>|</span>{1}",
                                                       string.Format(CultureInfo.CurrentCulture, "<a class=\"feedPrevEditButton" + (SetupInfo.WorkMode == WorkMode.Promo ? " promoAction" : "") + "\" href=\"{0}?docID={1}{3}\">{2}</a>", GetEditUrl(), Feed.Id, NewsResource.EditButton, UserIdAttribute),
                                                       string.Format(CultureInfo.CurrentCulture, "<a class=\"feedPrevEditButton" + (SetupInfo.WorkMode == WorkMode.Promo ? " promoAction" : "") + "\" href=\"javascript:;\" onclick=\"javascript:if(window.confirm('{0}'))FeedView.Remove('{1}',callbackRemove);\">{2}</a>", NewsResource.ConfirmRemoveMessage, Feed.Id, NewsResource.DeleteButton));
                }

                profileLink.Text = CoreContext.UserManager.GetUsers(new Guid(Feed.Creator)).RenderProfileLink(Community.Product.CommunityProduct.ID);

                if (Feed is FeedPoll)
                {
                    var  poll       = (FeedPoll)Feed;
                    bool isMakeVote = TenantUtil.DateTimeNow() <= poll.EndDate && !poll.IsUserVote(SecurityContext.CurrentAccount.ID.ToString());

                    var pollForm = new PollForm();
                    pollForm.VoteHandlerType = typeof(PollVoteHandler);
                    pollForm.Answered        = !isMakeVote || SecurityContext.DemoMode || (SetupInfo.WorkMode == WorkMode.Promo);
                    pollForm.Name            = poll.Caption;
                    pollForm.PollID          = poll.Id.ToString(CultureInfo.CurrentCulture);
                    pollForm.Singleton       = (poll.PollType == FeedPollType.SimpleAnswer);

                    pollForm.AdditionalParams = poll.Id.ToString(CultureInfo.CurrentCulture);
                    foreach (var variant in poll.Variants)
                    {
                        pollForm.AnswerVariants.Add(new PollForm.AnswerViarint()
                        {
                            ID        = variant.ID.ToString(CultureInfo.CurrentCulture),
                            Name      = variant.Name,
                            VoteCount = poll.GetVariantVoteCount(variant.ID)
                        });
                    }
                    pollHolder.Controls.Add(pollForm);
                }
                else
                {
                    pollHolder.Visible = false;
                    newsText.Visible   = true;
                }
            }
        }
        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>"
            });
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _settings = ForumManager.GetSettings(SettingsID);
            _forumManager = _settings.ForumManager;

            if (this.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 = 0;
            var posts = ForumDataProvider.GetPosts(TenantProvider.CurrentTenantID, Topic.ID, currentPageNumber, _settings.PostCountOnPage, out postCountInTopic);
            
            PageNavigator pageNavigator = new PageNavigator()
            {
                PageUrl = _settings.LinkProvider.PostList(Topic.ID),
                CurrentPageNumber = currentPageNumber,
                EntryCountOnPage = _settings.PostCountOnPage,
                VisiblePageCount = 5,
                EntryCount = postCountInTopic
            };

            bottomPageNavigatorHolder.Controls.Add(pageNavigator);

            int i = 0;
            foreach (Post post in posts)
            {
                PostControl 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;
                this.postListHolder.Controls.Add(postControl);
                i++;
            }

            ForumDataProvider.SetTopicVisit(Topic);

            if (Topic.Type == TopicType.Poll)
            {
                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();
                pollForm.VoteHandlerType = typeof(PollVoteHandler);
                pollForm.Answered =isVote ||Topic.Closed
                                    || !_forumManager.ValidateAccessSecurityAction(ForumAction.PollVote, q) 
                                    ||  ASC.Core.SecurityContext.DemoMode || (SetupInfo.WorkMode == WorkMode.Promo);

                pollForm.Name = q.Name;
                pollForm.PollID = q.ID.ToString();
                pollForm.Singleton = (q.Type == QuestionType.OneAnswer);
                pollForm.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>" });
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _settings     = ForumManager.GetSettings(SettingsID);
            _forumManager = _settings.ForumManager;

            if (this.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 = 0;
            var posts            = ForumDataProvider.GetPosts(TenantProvider.CurrentTenantID, Topic.ID, currentPageNumber, _settings.PostCountOnPage, out postCountInTopic);

            PageNavigator pageNavigator = new PageNavigator()
            {
                PageUrl           = _settings.LinkProvider.PostList(Topic.ID),
                CurrentPageNumber = currentPageNumber,
                EntryCountOnPage  = _settings.PostCountOnPage,
                VisiblePageCount  = 5,
                EntryCount        = postCountInTopic
            };

            bottomPageNavigatorHolder.Controls.Add(pageNavigator);

            int i = 0;

            foreach (Post post in posts)
            {
                PostControl 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;
                this.postListHolder.Controls.Add(postControl);
                i++;
            }

            ForumDataProvider.SetTopicVisit(Topic);

            if (Topic.Type == TopicType.Poll)
            {
                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();
                pollForm.VoteHandlerType = typeof(PollVoteHandler);
                pollForm.Answered        = isVote || Topic.Closed ||
                                           !_forumManager.ValidateAccessSecurityAction(ForumAction.PollVote, q) ||
                                           ASC.Core.SecurityContext.DemoMode || (SetupInfo.WorkMode == WorkMode.Promo);

                pollForm.Name             = q.Name;
                pollForm.PollID           = q.ID.ToString();
                pollForm.Singleton        = (q.Type == QuestionType.OneAnswer);
                pollForm.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>"
                });
            }
        }
        private async Task <ServiceResponse <List <GetPollFormDto> > > GetQuestionsDto(PollForm updatePollFormDto,
                                                                                       ServiceResponse <List <GetPollFormDto> > response,
                                                                                       ICollection <GetPollFormDto> questions)
        {
            //questions?.Clear();
            GetPollFormDto pollFormDto       = _mapper.Map <GetPollFormDto>(updatePollFormDto);
            var            questionsResponse = await _questionService.GetQuestions(updatePollFormDto.PollId);

            if (questionsResponse.Data == null)
            {
                return(response.Failure(questionsResponse.Message, questionsResponse.Code));
            }
            pollFormDto.Questions = questionsResponse.Data;

            questions?.Add(pollFormDto);
            Console.WriteLine(questions.Count);
            //questions?.Last().Questions.AddRange(questionsResponse.Data);
            //TODO: heavy refactor
            return(response.Success(new List <GetPollFormDto>(), questionsResponse.Message));
        }