Ejemplo n.º 1
0
        public bool VoteCallback(string pollID, List <string> selectedVariantIDs, string additionalParams, out string errorMessage)
        {
            errorMessage = "";
            var settingsID    = new Guid(additionalParams.Split(',')[0]);
            int idQuestion    = Convert.ToInt32(additionalParams.Split(',')[1]);
            var _forumManager = ForumManager.GetForumManager(settingsID);


            List <int> variantIDs = new List <int>(0);

            foreach (string id in selectedVariantIDs)
            {
                if (!String.IsNullOrEmpty(id))
                {
                    variantIDs.Add(Convert.ToInt32(id));
                }
            }

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

            if (SetupInfo.WorkMode == WorkMode.Promo ||
                q == null ||
                !_forumManager.ValidateAccessSecurityAction(ForumAction.PollVote, q) ||
                ForumDataProvider.IsUserVote(TenantProvider.CurrentTenantID, idQuestion, SecurityContext.CurrentAccount.ID))
            {
                errorMessage = Resources.ForumUCResource.ErrorAccessDenied;
                return(false);
            }

            try
            {
                ForumDataProvider.PollVote(TenantProvider.CurrentTenantID, idQuestion, variantIDs);
            }
            catch (Exception e)
            {
                errorMessage = e.Message.HtmlEncode();
                return(false);
            }

            var settings = ForumManager.GetSettings(settingsID);

            if (settings != null && settings.ActivityPublisher != null)
            {
                settings.ActivityPublisher.Vote(q.Name, q.TopicID);
            }

            return(true);
        }
        public bool VoteCallback(string pollID, List <string> selectedVariantIDs, string additionalParams, out string errorMessage)
        {
            errorMessage = "";
            int idQuestion    = Convert.ToInt32(additionalParams.Split(',')[1]);
            var _forumManager = Community.Forum.ForumManager.Settings.ForumManager;


            var variantIDs = new List <int>(0);

            foreach (var id in selectedVariantIDs)
            {
                if (!string.IsNullOrEmpty(id))
                {
                    variantIDs.Add(Convert.ToInt32(id));
                }
            }

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

            if (q == null ||
                !_forumManager.ValidateAccessSecurityAction(ForumAction.PollVote, q) ||
                ForumDataProvider.IsUserVote(TenantProvider.CurrentTenantID, idQuestion, SecurityContext.CurrentAccount.ID))
            {
                errorMessage = Resources.ForumUCResource.ErrorAccessDenied;
                return(false);
            }

            try
            {
                ForumDataProvider.PollVote(TenantProvider.CurrentTenantID, idQuestion, variantIDs);
            }
            catch (Exception e)
            {
                errorMessage = e.Message.HtmlEncode();
                return(false);
            }
            return(true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _settings     = Community.Forum.ForumManager.Settings;
            _forumManager = _settings.ForumManager;

            Utility.RegisterTypeForAjax(typeof(TagSuggest));

            _subject = "";

            int idTopic = 0;

            if (!String.IsNullOrEmpty(Request[_settings.TopicParamName]))
            {
                try
                {
                    idTopic = Convert.ToInt32(Request[_settings.TopicParamName]);
                }
                catch { idTopic = 0; }
            }

            if (idTopic == 0)
            {
                Response.Redirect(_forumManager.PreviousPage.Url);
                return;
            }
            topicId = idTopic;

            EditableTopic = ForumDataProvider.GetTopicByID(TenantProvider.CurrentTenantID, idTopic);
            if (EditableTopic == null)
            {
                Response.Redirect(_forumManager.PreviousPage.Url);
                return;
            }

            if (!_forumManager.ValidateAccessSecurityAction(ForumAction.TopicEdit, EditableTopic))
            {
                Response.Redirect(_forumManager.PreviousPage.Url);
                return;
            }

            _subject = EditableTopic.Title;

            _tagString = String.Join(",", EditableTopic.Tags.Select(x => x.Name));
            _tagValues = JsonConvert.SerializeObject(EditableTopic.Tags.Select(x => new List <object> {
                x.Name, x.ID
            }));

            if (EditableTopic.Type == TopicType.Informational)
            {
                _pollMaster.Visible = false;
            }
            else
            {
                _pollMaster.QuestionFieldID = "forum_subject";
                if (IsPostBack == false)
                {
                    var question = ForumDataProvider.GetPollByID(TenantProvider.CurrentTenantID, EditableTopic.QuestionID);
                    _pollMaster.Singleton = (question.Type == QuestionType.OneAnswer);
                    _pollMaster.Name      = question.Name;
                    _pollMaster.ID        = question.ID.ToString();

                    foreach (var variant in question.AnswerVariants)
                    {
                        _pollMaster.AnswerVariants.Add(new PollFormMaster.AnswerViarint()
                        {
                            ID   = variant.ID.ToString(),
                            Name = variant.Name
                        });
                    }
                }
            }


            #region IsPostBack
            if (IsPostBack)
            {
                if (EditableTopic.Type == TopicType.Informational)
                {
                    _subject = Request["forum_subject"].Trim();
                }
                else
                {
                    _subject = (_pollMaster.Name ?? "").Trim();
                }

                if (String.IsNullOrEmpty(_subject))
                {
                    _subject      = "";
                    _errorMessage = "<div class=\"errorBox\">" + Resources.ForumUCResource.ErrorSubjectEmpty + "</div>";
                    return;
                }

                if (EditableTopic.Type == TopicType.Poll && _pollMaster.AnswerVariants.Count < 2)
                {
                    _errorMessage = "<div class=\"errorBox\">" + Resources.ForumUCResource.ErrorPollVariantCount + "</div>";
                    return;
                }

                if (!String.IsNullOrEmpty(Request["forum_tags"]))
                {
                    _tagString = Request["forum_tags"].Trim();
                }
                else
                {
                    _tagString = "";
                }

                if (!String.IsNullOrEmpty(Request["forum_search_tags"]))
                {
                    _tagValues = Request["forum_search_tags"].Trim();
                }

                EditableTopic.Title = _subject;

                if (_forumManager.ValidateAccessSecurityAction(ForumAction.TagCreate, new Thread()
                {
                    ID = EditableTopic.ThreadID
                }))
                {
                    var removeTags = EditableTopic.Tags;
                    EditableTopic.Tags = CreateTags();

                    removeTags.RemoveAll(t => EditableTopic.Tags.Find(nt => nt.ID == t.ID) != null);

                    foreach (var tag in EditableTopic.Tags)
                    {
                        if (tag.ID == 0)
                        {
                            ForumDataProvider.CreateTag(TenantProvider.CurrentTenantID, EditableTopic.ID, tag.Name, tag.IsApproved);
                        }
                        else
                        {
                            ForumDataProvider.AttachTagToTopic(TenantProvider.CurrentTenantID, tag.ID, EditableTopic.ID);
                        }
                    }

                    removeTags.ForEach(t =>
                    {
                        ForumDataProvider.RemoveTagFromTopic(TenantProvider.CurrentTenantID, t.ID, EditableTopic.ID);
                    });
                }

                try
                {
                    if (EditableTopic.Type == TopicType.Poll)
                    {
                        List <AnswerVariant> variants = new List <AnswerVariant>();
                        int i = 1;
                        foreach (var answVariant in _pollMaster.AnswerVariants)
                        {
                            variants.Add(new AnswerVariant()
                            {
                                ID        = (String.IsNullOrEmpty(answVariant.ID) ? 0 : Convert.ToInt32(answVariant.ID)),
                                Name      = answVariant.Name,
                                SortOrder = i - 1
                            });
                            i++;
                        }

                        ForumDataProvider.UpdatePoll(TenantProvider.CurrentTenantID, EditableTopic.QuestionID,
                                                     _pollMaster.Singleton ? QuestionType.OneAnswer : QuestionType.SeveralAnswer,
                                                     EditableTopic.Title, variants);
                    }

                    ForumDataProvider.UpdateTopic(TenantProvider.CurrentTenantID, EditableTopic.ID, EditableTopic.Title,
                                                  EditableTopic.Sticky, EditableTopic.Closed);
                    FactoryIndexer <TopicWrapper> .UpdateAsync(EditableTopic);

                    _errorMessage = "<div class=\"okBox\">" + Resources.ForumUCResource.SuccessfullyEditTopicMessage + "</div>";
                    Response.Redirect(_forumManager.PreviousPage.Url);
                }
                catch (Exception ex)
                {
                    _errorMessage = "<div class=\"errorBox\">" + ex.Message.HtmlEncode() + "</div>";
                    return;
                }
            }
            #endregion
        }
        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>"
            });
        }
Ejemplo n.º 5
0
        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>"
                });
            }
        }