Пример #1
0
        protected void btnWatchTopic_Click(object sender, EventArgs e)
        {
            var forumTopic = ForumManager.GetTopicById(this.TopicId);

            if (forumTopic == null)
            {
                return;
            }

            if (!ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User))
            {
                string loginURL = SEOHelper.GetLoginPageUrl(true);
                Response.Redirect(loginURL);
            }

            var forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                     0, forumTopic.ForumTopicId, 1, 0).FirstOrDefault();

            if (forumSubscription == null)
            {
                forumSubscription = ForumManager.InsertSubscription(Guid.NewGuid(),
                                                                    NopContext.Current.User.CustomerId, 0, forumTopic.ForumTopicId, DateTime.Now);
            }
            else
            {
                ForumManager.DeleteSubscription(forumSubscription.ForumSubscriptionId);
            }

            CommonHelper.ReloadCurrentPage();
        }
Пример #2
0
        protected void btnWatchForum_Click(object sender, EventArgs e)
        {
            Forum forum = ForumManager.GetForumByID(this.ForumID);

            if (forum == null)
            {
                return;
            }

            if (!ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User))
            {
                string loginURL = CommonHelper.GetLoginPageURL(true);
                Response.Redirect(loginURL);
            }

            ForumSubscription forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerID,
                                                                                   forum.ForumID, 0, 1, 0).FirstOrDefault();

            if (forumSubscription == null)
            {
                forumSubscription = ForumManager.InsertSubscription(Guid.NewGuid(),
                                                                    NopContext.Current.User.CustomerID, forum.ForumID, 0, DateTime.Now);
            }
            else
            {
                ForumManager.DeleteSubscription(forumSubscription.ForumSubscriptionID);
            }

            CommonHelper.ReloadCurrentPage();
        }
Пример #3
0
        public static List <ForumSubscription> GetCurrentUserForumSubscriptions(int StartIndex, int PageSize, out int totalRecords)
        {
            if (PageSize <= 0)
            {
                PageSize = 10;
            }
            if (PageSize == int.MaxValue)
            {
                PageSize = int.MaxValue - 1;
            }

            int PageIndex = StartIndex / PageSize;

            totalRecords = 0;

            if (NopContext.Current.User == null)
            {
                return(new List <ForumSubscription>());
            }

            var result = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerId, 0, 0, PageSize, PageIndex, out totalRecords);

            return(result);
        }
Пример #4
0
        protected void BindData()
        {
            Forum forum = ForumManager.GetForumByID(this.ForumID);

            if (forum != null)
            {
                //hlNewTopic.Visible = ForumManager.IsUserAllowedToCreateTopic(NopContext.Current.User, forum);

                lblForumName.Text        = Server.HtmlEncode(forum.Name);
                lblForumDescription.Text = Server.HtmlEncode(forum.Description);

                hlNewTopic.NavigateUrl = SEOHelper.GetNewForumTopicURL(forum.ForumID);

                int totalRecords = 0;
                int pageSize     = 10;
                if (ForumManager.TopicsPageSize > 0)
                {
                    pageSize = ForumManager.TopicsPageSize;
                }

                ForumTopicCollection forumTopics = ForumManager.GetAllTopics(forum.ForumID, 0, string.Empty,
                                                                             false, pageSize, this.CurrentPageIndex, out totalRecords);
                if (forumTopics.Count > 0)
                {
                    this.topicsPager1.PageSize     = pageSize;
                    this.topicsPager1.TotalRecords = totalRecords;
                    this.topicsPager1.PageIndex    = this.CurrentPageIndex;

                    this.topicsPager2.PageSize     = pageSize;
                    this.topicsPager2.TotalRecords = totalRecords;
                    this.topicsPager2.PageIndex    = this.CurrentPageIndex;

                    rptrTopics.DataSource = forumTopics;
                    rptrTopics.DataBind();
                }

                //subsciption
                if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User))
                {
                    ForumSubscription forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerID,
                                                                                           forum.ForumID, 0, 1, 0).FirstOrDefault();

                    if (forumSubscription == null)
                    {
                        btnWatchForum.Text = GetLocaleResourceString("Forum.WatchForum");
                    }
                    else
                    {
                        btnWatchForum.Text = GetLocaleResourceString("Forum.UnwatchForum");
                    }
                }
                else
                {
                    btnWatchForum.Visible = false;
                }
            }
            else
            {
                Response.Redirect(SEOHelper.GetForumMainURL());
            }
        }
Пример #5
0
        private void BindData()
        {
            pnlError.Visible = false;

            txtTopicBodySimple.Visible = false;
            txtTopicBodyBBCode.Visible = false;
            txtTopicBodyHtml.Visible   = false;
            switch (ForumManager.ForumEditor)
            {
            case EditorTypeEnum.SimpleTextBox:
            {
                txtTopicBodySimple.Visible     = true;
                rfvTopicBody.ControlToValidate = "txtTopicBodySimple";
            }
            break;

            case EditorTypeEnum.BBCodeEditor:
            {
                txtTopicBodyBBCode.Visible     = true;
                rfvTopicBody.ControlToValidate = "txtTopicBodyBBCode";
            }
            break;

            case EditorTypeEnum.HtmlEditor:
            {
                txtTopicBodyHtml.Visible = true;
                rfvTopicBody.Enabled     = false;
            }
            break;

            default:
                break;
            }

            if (this.AddTopic)
            {
                #region Adding topic

                var forum = ForumManager.GetForumById(this.ForumId);
                if (forum == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainUrl());
                }

                if (NopContext.Current.User == null && ForumManager.AllowGuestsToCreateTopics)
                {
                    CustomerManager.CreateAnonymousUser();
                }

                if (!ForumManager.IsUserAllowedToCreateTopic(NopContext.Current.User, forum))
                {
                    string loginURL = SEOHelper.GetLoginPageUrl(true);
                    Response.Redirect(loginURL);
                }

                lblTitle.Text         = GetLocaleResourceString("Forum.NewTopic");
                phForumName.Visible   = true;
                lblForumName.Text     = Server.HtmlEncode(forum.Name);
                txtTopicTitle.Visible = true;
                txtTopicTitle.Text    = string.Empty;
                lblTopicTitle.Visible = false;
                lblTopicTitle.Text    = string.Empty;

                ctrlForumBreadcrumb.ForumId = forum.ForumId;
                ctrlForumBreadcrumb.BindData();

                phPriority.Visible  = ForumManager.IsUserAllowedToSetTopicPriority(NopContext.Current.User);
                phSubscribe.Visible = ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User);

                #endregion
            }
            else if (this.EditTopic)
            {
                #region Editing topic
                var forumTopic = ForumManager.GetTopicById(this.ForumTopicId);

                if (forumTopic == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainUrl());
                }

                if (!ForumManager.IsUserAllowedToEditTopic(NopContext.Current.User, forumTopic))
                {
                    string loginURL = SEOHelper.GetLoginPageUrl(true);
                    Response.Redirect(loginURL);
                }

                var forum = forumTopic.Forum;
                if (forum == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainUrl());
                }

                lblTitle.Text         = GetLocaleResourceString("Forum.EditTopic");
                phForumName.Visible   = true;
                lblForumName.Text     = Server.HtmlEncode(forum.Name);
                txtTopicTitle.Visible = true;
                txtTopicTitle.Text    = forumTopic.Subject;
                lblTopicTitle.Visible = false;
                lblTopicTitle.Text    = string.Empty;

                ctrlForumBreadcrumb.ForumTopicId = forumTopic.ForumTopicId;
                ctrlForumBreadcrumb.BindData();

                CommonHelper.SelectListItem(this.ddlPriority, forumTopic.TopicTypeId);

                var firstPost = forumTopic.FirstPost;
                if (firstPost != null)
                {
                    switch (ForumManager.ForumEditor)
                    {
                    case EditorTypeEnum.SimpleTextBox:
                    {
                        txtTopicBodySimple.Text = firstPost.Text;
                    }
                    break;

                    case EditorTypeEnum.BBCodeEditor:
                    {
                        txtTopicBodyBBCode.Text = firstPost.Text;
                    }
                    break;

                    case EditorTypeEnum.HtmlEditor:
                    {
                        txtTopicBodyHtml.Content = firstPost.Text;
                    }
                    break;

                    default:
                        break;
                    }
                }


                phPriority.Visible = ForumManager.IsUserAllowedToSetTopicPriority(NopContext.Current.User);
                //subscription
                if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User.CustomerId))
                {
                    phSubscribe.Visible = true;
                    var forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                             0, forumTopic.ForumTopicId, 1, 0).FirstOrDefault();
                    cbSubscribe.Checked = forumSubscription != null;
                }
                else
                {
                    phSubscribe.Visible = false;
                }
                #endregion
            }
            else if (this.AddPost)
            {
                #region Adding post

                var forumTopic = ForumManager.GetTopicById(this.ForumTopicId);
                if (forumTopic == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainUrl());
                }

                if (NopContext.Current.User == null && ForumManager.AllowGuestsToCreatePosts)
                {
                    CustomerManager.CreateAnonymousUser();
                }

                if (!ForumManager.IsUserAllowedToCreatePost(NopContext.Current.User, forumTopic))
                {
                    string loginURL = SEOHelper.GetLoginPageUrl(true);
                    Response.Redirect(loginURL);
                }

                ctrlForumBreadcrumb.ForumTopicId = forumTopic.ForumTopicId;
                ctrlForumBreadcrumb.BindData();

                lblTitle.Text         = GetLocaleResourceString("Forum.NewPost");
                phForumName.Visible   = false;
                lblForumName.Text     = string.Empty;
                txtTopicTitle.Visible = false;
                txtTopicTitle.Text    = string.Empty;
                lblTopicTitle.Visible = true;
                lblTopicTitle.Text    = Server.HtmlEncode(forumTopic.Subject);

                var quotePost = ForumManager.GetPostById(QuotePostId);
                if (quotePost != null && quotePost.TopicId == forumTopic.ForumTopicId)
                {
                    switch (ForumManager.ForumEditor)
                    {
                    case EditorTypeEnum.SimpleTextBox:
                        txtTopicBodySimple.Text = String.Format("{0}:\n{1}\n", CustomerManager.FormatUserName(quotePost.User), quotePost.Text);
                        break;

                    case EditorTypeEnum.BBCodeEditor:
                        txtTopicBodyBBCode.Text = String.Format("[quote={0}]{1}[/quote]", CustomerManager.FormatUserName(quotePost.User), BBCodeHelper.RemoveQuotes(quotePost.Text));
                        break;

                    case EditorTypeEnum.HtmlEditor:
                        txtTopicBodyHtml.Content = String.Format("<b>{0}:</b><p style=\"padding: 5px 5px 5px 5px; border: dashed 1px black; background-color: #ffffff;\">{1}</p>", CustomerManager.FormatUserName(quotePost.User), quotePost.Text);
                        break;
                    }
                }

                phPriority.Visible = false;
                //subscription
                if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User))
                {
                    phSubscribe.Visible = true;
                    var forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                             0, forumTopic.ForumTopicId, 1, 0).FirstOrDefault();
                    cbSubscribe.Checked = forumSubscription != null;
                }
                else
                {
                    phSubscribe.Visible = false;
                }
                #endregion
            }
            else if (this.EditPost)
            {
                #region Editing post

                var forumPost = ForumManager.GetPostById(this.ForumPostId);

                if (forumPost == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainUrl());
                }

                if (!ForumManager.IsUserAllowedToEditPost(NopContext.Current.User, forumPost))
                {
                    string loginURL = SEOHelper.GetLoginPageUrl(true);
                    Response.Redirect(loginURL);
                }

                var forumTopic = forumPost.Topic;
                if (forumTopic == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainUrl());
                }

                lblTitle.Text         = GetLocaleResourceString("Forum.EditPost");
                phForumName.Visible   = false;
                lblForumName.Text     = string.Empty;
                txtTopicTitle.Visible = false;
                txtTopicTitle.Text    = string.Empty;
                lblTopicTitle.Visible = true;
                lblTopicTitle.Text    = Server.HtmlEncode(forumTopic.Subject);

                ctrlForumBreadcrumb.ForumTopicId = forumTopic.ForumTopicId;
                ctrlForumBreadcrumb.BindData();


                switch (ForumManager.ForumEditor)
                {
                case EditorTypeEnum.SimpleTextBox:
                {
                    txtTopicBodySimple.Text = forumPost.Text;
                }
                break;

                case EditorTypeEnum.BBCodeEditor:
                {
                    txtTopicBodyBBCode.Text = forumPost.Text;
                }
                break;

                case EditorTypeEnum.HtmlEditor:
                {
                    txtTopicBodyHtml.Content = forumPost.Text;
                }
                break;

                default:
                    break;
                }

                phPriority.Visible = false;
                //subscription
                if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User.CustomerId))
                {
                    phSubscribe.Visible = true;
                    var forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                             0, forumTopic.ForumTopicId, 1, 0).FirstOrDefault();
                    cbSubscribe.Checked = forumSubscription != null;
                }
                else
                {
                    phSubscribe.Visible = false;
                }
                #endregion
            }
            else
            {
                Response.Redirect(SEOHelper.GetForumMainUrl());
            }
        }
Пример #6
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string text = string.Empty;

                switch (ForumManager.ForumEditor)
                {
                case EditorTypeEnum.SimpleTextBox:
                {
                    text = txtTopicBodySimple.Text.Trim();
                }
                break;

                case EditorTypeEnum.BBCodeEditor:
                {
                    text = txtTopicBodyBBCode.Text.Trim();
                }
                break;

                case EditorTypeEnum.HtmlEditor:
                {
                    text = txtTopicBodyHtml.Content;
                }
                break;

                default:
                    break;
                }

                string subject   = txtTopicTitle.Text;
                var    topicType = ForumTopicTypeEnum.Normal;
                bool   subscribe = cbSubscribe.Checked;

                string IPAddress = NopContext.Current.UserHostAddress;

                DateTime nowDT = DateTime.UtcNow;

                if (ForumManager.IsUserAllowedToSetTopicPriority(NopContext.Current.User))
                {
                    topicType = (ForumTopicTypeEnum)Enum.ToObject(typeof(ForumTopicTypeEnum), int.Parse(ddlPriority.SelectedItem.Value));
                }

                text = text.Trim();
                if (String.IsNullOrEmpty(text))
                {
                    throw new NopException(GetLocaleResourceString("Forum.TextCannotBeEmpty"));
                }

                if (this.AddTopic)
                {
                    #region Adding topic
                    var forum = ForumManager.GetForumById(this.ForumId);
                    if (forum == null)
                    {
                        Response.Redirect(SEOHelper.GetForumMainUrl());
                    }

                    if (!ForumManager.IsUserAllowedToCreateTopic(NopContext.Current.User, forum))
                    {
                        string loginURL = SEOHelper.GetLoginPageUrl(true);
                        Response.Redirect(loginURL);
                    }

                    subject = subject.Trim();
                    if (String.IsNullOrEmpty(subject))
                    {
                        throw new NopException(GetLocaleResourceString("Forum.TopicSubjectCannotBeEmpty"));
                    }

                    var forumTopic = ForumManager.InsertTopic(forum.ForumId, NopContext.Current.User.CustomerId,
                                                              topicType, subject, 0, 0, 0, 0, null, nowDT, nowDT, true);

                    var forumPost = ForumManager.InsertPost(forumTopic.ForumTopicId, NopContext.Current.User.CustomerId,
                                                            text, IPAddress, nowDT, nowDT, false);

                    forumTopic = ForumManager.UpdateTopic(forumTopic.ForumTopicId, forumTopic.ForumId,
                                                          forumTopic.UserId, forumTopic.TopicType, forumTopic.Subject, 1,
                                                          0, forumPost.ForumPostId, forumTopic.UserId,
                                                          forumPost.CreatedOn, forumTopic.CreatedOn, nowDT);

                    //subscription
                    if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User))
                    {
                        if (subscribe)
                        {
                            var forumSubscription = ForumManager.InsertSubscription(Guid.NewGuid(),
                                                                                    NopContext.Current.User.CustomerId, 0, forumTopic.ForumTopicId, nowDT);
                        }
                    }

                    string topicURL = SEOHelper.GetForumTopicUrl(forumTopic);
                    Response.Redirect(topicURL);
                    #endregion
                }
                else if (this.EditTopic)
                {
                    #region Editing topic
                    var forumTopic = ForumManager.GetTopicById(this.ForumTopicId);
                    if (forumTopic == null)
                    {
                        Response.Redirect(SEOHelper.GetForumMainUrl());
                    }

                    if (!ForumManager.IsUserAllowedToEditTopic(NopContext.Current.User, forumTopic))
                    {
                        string loginURL = SEOHelper.GetLoginPageUrl(true);
                        Response.Redirect(loginURL);
                    }

                    subject = subject.Trim();
                    if (String.IsNullOrEmpty(subject))
                    {
                        throw new NopException(GetLocaleResourceString("Forum.TopicSubjectCannotBeEmpty"));
                    }

                    forumTopic = ForumManager.UpdateTopic(forumTopic.ForumTopicId, forumTopic.ForumId,
                                                          forumTopic.UserId, topicType, subject, forumTopic.NumPosts,
                                                          forumTopic.Views, forumTopic.LastPostId, forumTopic.LastPostUserId,
                                                          forumTopic.LastPostTime, forumTopic.CreatedOn, nowDT);

                    var firstPost = forumTopic.FirstPost;
                    if (firstPost != null)
                    {
                        firstPost = ForumManager.UpdatePost(firstPost.ForumPostId, firstPost.TopicId,
                                                            firstPost.UserId, text, firstPost.IPAddress, firstPost.CreatedOn, nowDT);
                    }
                    else
                    {
                        //error
                        firstPost = ForumManager.InsertPost(forumTopic.ForumTopicId,
                                                            forumTopic.UserId, text, IPAddress, forumTopic.CreatedOn, nowDT, false);
                    }

                    //subscription
                    if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User.CustomerId))
                    {
                        var forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                                 0, forumTopic.ForumTopicId, 1, 0).FirstOrDefault();
                        if (subscribe)
                        {
                            if (forumSubscription == null)
                            {
                                forumSubscription = ForumManager.InsertSubscription(Guid.NewGuid(),
                                                                                    NopContext.Current.User.CustomerId, 0, forumTopic.ForumTopicId, nowDT);
                            }
                        }
                        else
                        {
                            if (forumSubscription != null)
                            {
                                ForumManager.DeleteSubscription(forumSubscription.ForumSubscriptionId);
                            }
                        }
                    }

                    string topicURL = SEOHelper.GetForumTopicUrl(forumTopic);
                    Response.Redirect(topicURL);
                    #endregion
                }
                else if (this.AddPost)
                {
                    #region Adding post
                    var forumTopic = ForumManager.GetTopicById(this.ForumTopicId);
                    if (forumTopic == null)
                    {
                        Response.Redirect(SEOHelper.GetForumMainUrl());
                    }

                    if (!ForumManager.IsUserAllowedToCreatePost(NopContext.Current.User, forumTopic))
                    {
                        string loginURL = SEOHelper.GetLoginPageUrl(true);
                        Response.Redirect(loginURL);
                    }

                    var forumPost = ForumManager.InsertPost(this.ForumTopicId, NopContext.Current.User.CustomerId,
                                                            text, IPAddress, nowDT, nowDT, true);

                    //subscription
                    if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User.CustomerId))
                    {
                        var forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                                 0, forumPost.TopicId, 1, 0).FirstOrDefault();
                        if (subscribe)
                        {
                            if (forumSubscription == null)
                            {
                                forumSubscription = ForumManager.InsertSubscription(Guid.NewGuid(),
                                                                                    NopContext.Current.User.CustomerId, 0, forumPost.TopicId, nowDT);
                            }
                        }
                        else
                        {
                            if (forumSubscription != null)
                            {
                                ForumManager.DeleteSubscription(forumSubscription.ForumSubscriptionId);
                            }
                        }
                    }


                    int pageSize = 10;
                    if (ForumManager.PostsPageSize > 0)
                    {
                        pageSize = ForumManager.PostsPageSize;
                    }
                    int    pageIndex = ForumManager.CalculateTopicPageIndex(forumPost.TopicId, pageSize, forumPost.ForumPostId);
                    string topicURL  = SEOHelper.GetForumTopicUrl(forumPost.TopicId, "p", pageIndex + 1, forumPost.ForumPostId);
                    Response.Redirect(topicURL);
                    #endregion
                }
                else if (this.EditPost)
                {
                    #region Editing post
                    var forumPost = ForumManager.GetPostById(this.ForumPostId);
                    if (forumPost == null)
                    {
                        Response.Redirect(SEOHelper.GetForumMainUrl());
                    }

                    if (!ForumManager.IsUserAllowedToEditPost(NopContext.Current.User, forumPost))
                    {
                        string loginURL = SEOHelper.GetLoginPageUrl(true);
                        Response.Redirect(loginURL);
                    }

                    forumPost = ForumManager.UpdatePost(forumPost.ForumPostId, forumPost.TopicId,
                                                        forumPost.UserId, text, forumPost.IPAddress, forumPost.CreatedOn, nowDT);

                    //subscription
                    if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User.CustomerId))
                    {
                        var forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                                 0, forumPost.TopicId, 1, 0).FirstOrDefault();
                        if (subscribe)
                        {
                            if (forumSubscription == null)
                            {
                                forumSubscription = ForumManager.InsertSubscription(Guid.NewGuid(),
                                                                                    NopContext.Current.User.CustomerId, 0, forumPost.TopicId, nowDT);
                            }
                        }
                        else
                        {
                            if (forumSubscription != null)
                            {
                                ForumManager.DeleteSubscription(forumSubscription.ForumSubscriptionId);
                            }
                        }
                    }

                    int pageSize = 10;
                    if (ForumManager.PostsPageSize > 0)
                    {
                        pageSize = ForumManager.PostsPageSize;
                    }
                    int    pageIndex = ForumManager.CalculateTopicPageIndex(forumPost.TopicId, pageSize, forumPost.ForumPostId);
                    string topicURL  = SEOHelper.GetForumTopicUrl(forumPost.TopicId, "p", pageIndex + 1, forumPost.ForumPostId);
                    Response.Redirect(topicURL);
                    #endregion
                }
            }
            catch (Exception exc)
            {
                pnlError.Visible   = true;
                lErrorMessage.Text = Server.HtmlEncode(exc.Message);
            }
        }
Пример #7
0
        private void BindData()
        {
            ForumTopic forumTopic = ForumManager.GetTopicByID(this.TopicID, true);

            if (forumTopic != null)
            {
                btnEdit.Visible      = ForumManager.IsUserAllowedToEditTopic(NopContext.Current.User, forumTopic);
                btnDelete.Visible    = ForumManager.IsUserAllowedToDeleteTopic(NopContext.Current.User, forumTopic);
                btnMoveTopic.Visible = ForumManager.IsUserAllowedToMoveTopic(NopContext.Current.User, forumTopic);
                //btnReply.Visible = ForumManager.IsUserAllowedToCreatePost(NopContext.Current.User, forumTopic);

                lblTopicSubject.Text = Server.HtmlEncode(forumTopic.Subject);

                int totalRecords = 0;
                int pageSize     = 10;
                if (ForumManager.PostsPageSize > 0)
                {
                    pageSize = ForumManager.PostsPageSize;
                }

                ForumPostCollection forumPosts = ForumManager.GetAllPosts(forumTopic.ForumTopicID, 0, string.Empty,
                                                                          pageSize, this.CurrentPageIndex, out totalRecords);
                if (forumPosts.Count > 0)
                {
                    this.postsPager1.PageSize     = pageSize;
                    this.postsPager1.TotalRecords = totalRecords;
                    this.postsPager1.PageIndex    = this.CurrentPageIndex;

                    this.postsPager2.PageSize     = pageSize;
                    this.postsPager2.TotalRecords = totalRecords;
                    this.postsPager2.PageIndex    = this.CurrentPageIndex;

                    rptrPosts.DataSource = forumPosts;
                    rptrPosts.DataBind();
                }

                //subsciption
                if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User))
                {
                    ForumSubscription forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerID,
                                                                                           0, forumTopic.ForumTopicID, 1, 0).FirstOrDefault();

                    if (forumSubscription == null)
                    {
                        btnWatchTopic.Text  = GetLocaleResourceString("Forum.WatchTopic");
                        btnWatchTopic2.Text = GetLocaleResourceString("Forum.WatchTopic");
                    }
                    else
                    {
                        btnWatchTopic.Text  = GetLocaleResourceString("Forum.UnwatchTopic");
                        btnWatchTopic2.Text = GetLocaleResourceString("Forum.UnwatchTopic");
                    }
                }
                else
                {
                    btnWatchTopic.Visible  = false;
                    btnWatchTopic2.Visible = false;
                }
            }
            else
            {
                Response.Redirect(SEOHelper.GetForumMainURL());
            }
        }
        private void BindData()
        {
            pnlError.Visible = false;

            txtTopicBodySimple.Visible = false;
            txtTopicBodyBBCode.Visible = false;
            txtTopicBodyHtml.Visible   = false;
            switch (ForumManager.ForumEditor)
            {
            case EditorTypeEnum.SimpleTextBox:
            {
                txtTopicBodySimple.Visible     = true;
                rfvTopicBody.ControlToValidate = "txtTopicBodySimple";
            }
            break;

            case EditorTypeEnum.BBCodeEditor:
            {
                txtTopicBodyBBCode.Visible     = true;
                rfvTopicBody.ControlToValidate = "txtTopicBodyBBCode";
            }
            break;

            case EditorTypeEnum.HtmlEditor:
            {
                txtTopicBodyHtml.Visible = true;
                rfvTopicBody.Enabled     = false;
            }
            break;

            default:
                break;
            }

            if (this.AddTopic)
            {
                #region Adding topic

                Forum forum = ForumManager.GetForumByID(this.ForumID);
                if (forum == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainURL());
                }

                if (!ForumManager.IsUserAllowedToCreateTopic(NopContext.Current.User, forum))
                {
                    string loginURL = CommonHelper.GetLoginPageURL(true);
                    Response.Redirect(loginURL);
                }

                lblTitle.Text         = GetLocaleResourceString("Forum.NewTopic");
                phForumName.Visible   = true;
                lblForumName.Text     = Server.HtmlEncode(forum.Name);
                txtTopicTitle.Visible = true;
                txtTopicTitle.Text    = string.Empty;
                lblTopicTitle.Visible = false;
                lblTopicTitle.Text    = string.Empty;

                ctrlForumBreadcrumb.ForumID = forum.ForumID;
                ctrlForumBreadcrumb.BindData();

                phPriority.Visible  = ForumManager.IsUserAllowedToSetTopicPriority(NopContext.Current.User);
                phSubscribe.Visible = ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User);

                #endregion
            }
            else if (this.EditTopic)
            {
                #region Editing topic
                ForumTopic forumTopic = ForumManager.GetTopicByID(this.ForumTopicID);

                if (forumTopic == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainURL());
                }

                if (!ForumManager.IsUserAllowedToEditTopic(NopContext.Current.User, forumTopic))
                {
                    string loginURL = CommonHelper.GetLoginPageURL(true);
                    Response.Redirect(loginURL);
                }

                Forum forum = forumTopic.Forum;
                if (forum == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainURL());
                }

                lblTitle.Text         = GetLocaleResourceString("Forum.EditTopic");
                phForumName.Visible   = true;
                lblForumName.Text     = Server.HtmlEncode(forum.Name);
                txtTopicTitle.Visible = true;
                txtTopicTitle.Text    = forumTopic.Subject;
                lblTopicTitle.Visible = false;
                lblTopicTitle.Text    = string.Empty;

                ctrlForumBreadcrumb.ForumTopicID = forumTopic.ForumTopicID;
                ctrlForumBreadcrumb.BindData();

                CommonHelper.SelectListItem(this.ddlPriority, forumTopic.TopicTypeID);

                ForumPost firstPost = forumTopic.FirstPost;
                if (firstPost != null)
                {
                    switch (ForumManager.ForumEditor)
                    {
                    case EditorTypeEnum.SimpleTextBox:
                    {
                        txtTopicBodySimple.Text = firstPost.Text;
                    }
                    break;

                    case EditorTypeEnum.BBCodeEditor:
                    {
                        txtTopicBodyBBCode.Text = firstPost.Text;
                    }
                    break;

                    case EditorTypeEnum.HtmlEditor:
                    {
                        txtTopicBodyHtml.Value = firstPost.Text;
                    }
                    break;

                    default:
                        break;
                    }
                }


                phPriority.Visible = ForumManager.IsUserAllowedToSetTopicPriority(NopContext.Current.User);
                //subscription
                if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User.CustomerID))
                {
                    phSubscribe.Visible = true;
                    ForumSubscription forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerID,
                                                                                           0, forumTopic.ForumTopicID, 1, 0).FirstOrDefault();
                    cbSubscribe.Checked = forumSubscription != null;
                }
                else
                {
                    phSubscribe.Visible = false;
                }
                #endregion
            }
            else if (this.AddPost)
            {
                #region Adding post

                ForumTopic forumTopic = ForumManager.GetTopicByID(this.ForumTopicID);
                if (forumTopic == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainURL());
                }

                if (!ForumManager.IsUserAllowedToCreatePost(NopContext.Current.User, forumTopic))
                {
                    string loginURL = CommonHelper.GetLoginPageURL(true);
                    Response.Redirect(loginURL);
                }

                ctrlForumBreadcrumb.ForumTopicID = forumTopic.ForumTopicID;
                ctrlForumBreadcrumb.BindData();

                lblTitle.Text         = GetLocaleResourceString("Forum.NewPost");
                phForumName.Visible   = false;
                lblForumName.Text     = string.Empty;
                txtTopicTitle.Visible = false;
                txtTopicTitle.Text    = string.Empty;
                lblTopicTitle.Visible = true;
                lblTopicTitle.Text    = Server.HtmlEncode(forumTopic.Subject);

                phPriority.Visible = false;
                //subscription
                if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User))
                {
                    phSubscribe.Visible = true;
                    ForumSubscription forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerID,
                                                                                           0, forumTopic.ForumTopicID, 1, 0).FirstOrDefault();
                    cbSubscribe.Checked = forumSubscription != null;
                }
                else
                {
                    phSubscribe.Visible = false;
                }
                #endregion
            }
            else if (this.EditPost)
            {
                #region Editing post

                ForumPost forumPost = ForumManager.GetPostByID(this.ForumPostID);

                if (forumPost == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainURL());
                }

                if (!ForumManager.IsUserAllowedToEditPost(NopContext.Current.User, forumPost))
                {
                    string loginURL = CommonHelper.GetLoginPageURL(true);
                    Response.Redirect(loginURL);
                }

                ForumTopic forumTopic = forumPost.Topic;
                if (forumTopic == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainURL());
                }

                lblTitle.Text         = GetLocaleResourceString("Forum.EditPost");
                phForumName.Visible   = false;
                lblForumName.Text     = string.Empty;
                txtTopicTitle.Visible = false;
                txtTopicTitle.Text    = string.Empty;
                lblTopicTitle.Visible = true;
                lblTopicTitle.Text    = Server.HtmlEncode(forumTopic.Subject);

                ctrlForumBreadcrumb.ForumTopicID = forumTopic.ForumTopicID;
                ctrlForumBreadcrumb.BindData();


                switch (ForumManager.ForumEditor)
                {
                case EditorTypeEnum.SimpleTextBox:
                {
                    txtTopicBodySimple.Text = forumPost.Text;
                }
                break;

                case EditorTypeEnum.BBCodeEditor:
                {
                    txtTopicBodyBBCode.Text = forumPost.Text;
                }
                break;

                case EditorTypeEnum.HtmlEditor:
                {
                    txtTopicBodyHtml.Value = forumPost.Text;
                }
                break;

                default:
                    break;
                }

                phPriority.Visible = false;
                //subscription
                if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User.CustomerID))
                {
                    phSubscribe.Visible = true;
                    ForumSubscription forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerID,
                                                                                           0, forumTopic.ForumTopicID, 1, 0).FirstOrDefault();
                    cbSubscribe.Checked = forumSubscription != null;
                }
                else
                {
                    phSubscribe.Visible = false;
                }
                #endregion
            }
            else
            {
                Response.Redirect(SEOHelper.GetForumMainURL());
            }
        }
Пример #9
0
        private void BindData()
        {
            var forumTopic = ForumManager.GetTopicById(this.TopicId, true);

            if (forumTopic != null)
            {
                btnEdit.Visible         = ForumManager.IsUserAllowedToEditTopic(NopContext.Current.User, forumTopic);
                btnDelete.Visible       = ForumManager.IsUserAllowedToDeleteTopic(NopContext.Current.User, forumTopic);
                btnDelete.OnClientClick = string.Format("return confirm('{0}')", GetLocaleResourceString("Common.AreYouSure"));
                btnMoveTopic.Visible    = ForumManager.IsUserAllowedToMoveTopic(NopContext.Current.User, forumTopic);

                lblTopicSubject.Text = Server.HtmlEncode(forumTopic.Subject);

                int totalRecords = 0;
                int pageSize     = 10;
                if (ForumManager.PostsPageSize > 0)
                {
                    pageSize = ForumManager.PostsPageSize;
                }

                var forumPosts = ForumManager.GetAllPosts(forumTopic.ForumTopicId, 0, string.Empty,
                                                          pageSize, this.CurrentPageIndex, out totalRecords);
                if (forumPosts.Count > 0)
                {
                    this.postsPager1.PageSize     = pageSize;
                    this.postsPager1.TotalRecords = totalRecords;
                    this.postsPager1.PageIndex    = this.CurrentPageIndex;

                    this.postsPager2.PageSize     = pageSize;
                    this.postsPager2.TotalRecords = totalRecords;
                    this.postsPager2.PageIndex    = this.CurrentPageIndex;

                    rptrPosts.DataSource = forumPosts;
                    rptrPosts.DataBind();
                }

                //subsciption
                if (ForumManager.IsUserAllowedToSubscribe(NopContext.Current.User))
                {
                    var forumSubscription = ForumManager.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                             0, forumTopic.ForumTopicId, 1, 0).FirstOrDefault();

                    if (forumSubscription == null)
                    {
                        btnWatchTopic.Text  = GetLocaleResourceString("Forum.WatchTopic");
                        btnWatchTopic2.Text = GetLocaleResourceString("Forum.WatchTopic");
                    }
                    else
                    {
                        btnWatchTopic.Text  = GetLocaleResourceString("Forum.UnwatchTopic");
                        btnWatchTopic2.Text = GetLocaleResourceString("Forum.UnwatchTopic");
                    }
                }
                else
                {
                    btnWatchTopic.Visible  = false;
                    btnWatchTopic2.Visible = false;
                }
            }
            else
            {
                Response.Redirect(SEOHelper.GetForumMainUrl());
            }
        }
 public void BindData()
 {
     gvForumSubscriptions.DataSource = ForumManager.GetAllSubscriptions(CustomerId, 0, 0, int.MaxValue, 0);
     gvForumSubscriptions.DataBind();
 }