コード例 #1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int forumPostId = 0;

            int.TryParse(lblForumPostId.Text, out forumPostId);
            var forumPost = ForumManager.GetPostById(forumPostId);

            if (forumPost != null)
            {
                var forumTopic = forumPost.Topic;
                if (!ForumManager.IsUserAllowedToDeletePost(NopContext.Current.User, forumPost))
                {
                    string loginURL = SEOHelper.GetLoginPageUrl(true);
                    Response.Redirect(loginURL);
                }

                ForumManager.DeletePost(forumPost.ForumPostId);

                string url = string.Empty;
                //get topic one more time because it can be deleted
                forumTopic = ForumManager.GetTopicById(forumPost.TopicId);
                if (forumTopic != null)
                {
                    url = SEOHelper.GetForumTopicUrl(forumTopic.ForumTopicId);
                }
                else
                {
                    url = SEOHelper.GetForumMainUrl();
                }
                Response.Redirect(url);
            }
        }
コード例 #2
0
        protected void BindData()
        {
            var forum = this.ForumService.GetForumById(this.ForumId);

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

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

                hlNewTopic.NavigateUrl = SEOHelper.GetNewForumTopicUrl(forum.ForumId);

                int pageSize = 10;
                if (this.ForumService.TopicsPageSize > 0)
                {
                    pageSize = this.ForumService.TopicsPageSize;
                }

                var forumTopics = this.ForumService.GetAllTopics(forum.ForumId, 0, string.Empty,
                                                                 ForumSearchTypeEnum.All, 0, this.CurrentPageIndex, pageSize);
                if (forumTopics.Count > 0)
                {
                    this.topicsPager1.PageSize     = pageSize;
                    this.topicsPager1.TotalRecords = forumTopics.TotalCount;
                    this.topicsPager1.PageIndex    = this.CurrentPageIndex;

                    this.topicsPager2.PageSize     = pageSize;
                    this.topicsPager2.TotalRecords = forumTopics.TotalCount;
                    this.topicsPager2.PageIndex    = this.CurrentPageIndex;

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

                //subsciption
                if (this.ForumService.IsUserAllowedToSubscribe(NopContext.Current.User))
                {
                    var forumSubscription = this.ForumService.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                                  forum.ForumId, 0, 0, 1).FirstOrDefault();

                    if (forumSubscription == null)
                    {
                        btnWatchForum.Text = GetLocaleResourceString("Forum.WatchForum");
                    }
                    else
                    {
                        btnWatchForum.Text = GetLocaleResourceString("Forum.UnwatchForum");
                    }
                }
                else
                {
                    btnWatchForum.Visible = false;
                }
            }
            else
            {
                Response.Redirect(SEOHelper.GetForumMainUrl());
            }
        }
コード例 #3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                var forumTopic = this.ForumService.GetTopicById(this.ForumTopicId);
                if (forumTopic == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainUrl());
                }

                this.ForumService.MoveTopic(forumTopic.ForumTopicId, ctrlForumSelector.SelectedForumId);
                string topicURL = SEOHelper.GetForumTopicUrl(forumTopic);
                Response.Redirect(topicURL);
            }
            catch (Exception exc)
            {
                pnlError.Visible   = true;
                lErrorMessage.Text = Server.HtmlEncode(exc.Message);
            }
        }
コード例 #4
0
 protected void btnCancel_Click(object sender, EventArgs e)
 {
     try
     {
         var forumTopic = this.ForumService.GetTopicById(this.ForumTopicId);
         if (forumTopic != null)
         {
             string topicUrl = SEOHelper.GetForumTopicUrl(forumTopic);
             Response.Redirect(topicUrl);
         }
         else
         {
             Response.Redirect(SEOHelper.GetForumMainUrl());
         }
     }
     catch (Exception exc)
     {
         pnlError.Visible   = true;
         lErrorMessage.Text = Server.HtmlEncode(exc.Message);
     }
 }
コード例 #5
0
        private void BindData()
        {
            pnlError.Visible = false;

            var forumTopic = this.ForumService.GetTopicById(this.ForumTopicId);

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

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

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

            ctrlForumSelector.SelectedForumId = forumTopic.ForumId;
            ctrlForumSelector.BindData();
        }
コード例 #6
0
ファイル: ForumBreadcrumb.ascx.cs プロジェクト: terry2012/DSV
        public void BindData()
        {
            hlHome.NavigateUrl       = CommonHelper.GetStoreLocation();
            hlForumsHome.NavigateUrl = SEOHelper.GetForumMainUrl();

            //topic
            var forumTopic = ForumManager.GetTopicById(this.ForumTopicId);

            if (forumTopic != null)
            {
                hlForumTopic.NavigateUrl = SEOHelper.GetForumTopicUrl(forumTopic);
                hlForumTopic.Text        = Server.HtmlEncode(forumTopic.Subject);
            }
            else
            {
                phForumTopic.Visible = false;
            }

            //forum
            Forum forum = null;

            if (forumTopic != null)
            {
                forum = ForumManager.GetForumById(forumTopic.ForumId);
            }
            else
            {
                forum = ForumManager.GetForumById(this.ForumId);
            }

            if (forum != null)
            {
                hlForum.NavigateUrl = SEOHelper.GetForumUrl(forum);
                hlForum.Text        = Server.HtmlEncode(forum.Name);
            }
            else
            {
                phForum.Visible = false;
            }

            //forum group
            ForumGroup forumGroup = null;

            if (forum != null)
            {
                forumGroup = ForumManager.GetForumGroupById(forum.ForumGroupId);
            }
            else
            {
                forumGroup = ForumManager.GetForumGroupById(this.ForumGroupId);
            }

            if (forumGroup != null)
            {
                hlForumGroup.NavigateUrl = SEOHelper.GetForumGroupUrl(forumGroup);
                hlForumGroup.Text        = Server.HtmlEncode(forumGroup.Name);
            }
            else
            {
                phForumTopic.Visible = false;
            }
        }
コード例 #7
0
        private void BindData()
        {
            pnlError.Visible = false;

            txtTopicBodySimple.Visible = false;
            txtTopicBodyBBCode.Visible = false;
            txtTopicBodyHtml.Visible   = false;
            switch (this.ForumService.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 = this.ForumService.GetForumById(this.ForumId);
                if (forum == null)
                {
                    Response.Redirect(SEOHelper.GetForumMainUrl());
                }

                if (NopContext.Current.User == null && this.ForumService.AllowGuestsToCreateTopics)
                {
                    this.CustomerService.CreateAnonymousUser();
                }

                if (!this.ForumService.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  = this.ForumService.IsUserAllowedToSetTopicPriority(NopContext.Current.User);
                phSubscribe.Visible = this.ForumService.IsUserAllowedToSubscribe(NopContext.Current.User);

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

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

                if (!this.ForumService.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 (this.ForumService.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 = this.ForumService.IsUserAllowedToSetTopicPriority(NopContext.Current.User);
                //subscription
                if (this.ForumService.IsUserAllowedToSubscribe(NopContext.Current.User))
                {
                    phSubscribe.Visible = true;
                    var forumSubscription = this.ForumService.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                                  0, forumTopic.ForumTopicId, 0, 1).FirstOrDefault();
                    cbSubscribe.Checked = forumSubscription != null;
                }
                else
                {
                    phSubscribe.Visible = false;
                }
                #endregion
            }
            else if (this.AddPost)
            {
                #region Adding post

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

                if (NopContext.Current.User == null && this.ForumService.AllowGuestsToCreatePosts)
                {
                    this.CustomerService.CreateAnonymousUser();
                }

                if (!this.ForumService.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 = this.ForumService.GetPostById(QuotePostId);
                if (quotePost != null && quotePost.TopicId == forumTopic.ForumTopicId)
                {
                    switch (this.ForumService.ForumEditor)
                    {
                    case EditorTypeEnum.SimpleTextBox:
                        txtTopicBodySimple.Text = String.Format("{0}:\n{1}\n", quotePost.User.FormatUserName(), quotePost.Text);
                        break;

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

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

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

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

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

                if (!this.ForumService.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 (this.ForumService.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 (this.ForumService.IsUserAllowedToSubscribe(NopContext.Current.User))
                {
                    phSubscribe.Visible = true;
                    var forumSubscription = this.ForumService.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                                  0, forumTopic.ForumTopicId, 0, 1).FirstOrDefault();
                    cbSubscribe.Checked = forumSubscription != null;
                }
                else
                {
                    phSubscribe.Visible = false;
                }
                #endregion
            }
            else
            {
                Response.Redirect(SEOHelper.GetForumMainUrl());
            }
        }
コード例 #8
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string text = string.Empty;

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

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

                case EditorTypeEnum.HtmlEditor:
                {
                    text = txtTopicBodyHtml.Value;
                }
                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 (this.ForumService.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 = this.ForumService.GetForumById(this.ForumId);
                    if (forum == null)
                    {
                        Response.Redirect(SEOHelper.GetForumMainUrl());
                    }

                    if (!this.ForumService.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"));
                    }

                    //forum topic
                    var forumTopic = new ForumTopic()
                    {
                        ForumId     = forum.ForumId,
                        UserId      = NopContext.Current.User.CustomerId,
                        TopicTypeId = (int)topicType,
                        Subject     = subject,
                        CreatedOn   = nowDT,
                        UpdatedOn   = nowDT
                    };
                    this.ForumService.InsertTopic(forumTopic, true);

                    //forum post
                    var forumPost = new ForumPost()
                    {
                        TopicId   = forumTopic.ForumTopicId,
                        UserId    = NopContext.Current.User.CustomerId,
                        Text      = text,
                        IPAddress = IPAddress,
                        CreatedOn = nowDT,
                        UpdatedOn = nowDT
                    };
                    this.ForumService.InsertPost(forumPost, false);

                    //update forum topic
                    forumTopic.NumPosts       = 1;
                    forumTopic.LastPostId     = forumPost.ForumPostId;
                    forumTopic.LastPostUserId = forumPost.UserId;
                    forumTopic.LastPostTime   = forumPost.CreatedOn;
                    forumTopic.UpdatedOn      = nowDT;
                    this.ForumService.UpdateTopic(forumTopic);

                    //subscription
                    if (this.ForumService.IsUserAllowedToSubscribe(NopContext.Current.User))
                    {
                        if (subscribe)
                        {
                            var forumSubscription = new ForumSubscription()
                            {
                                SubscriptionGuid = Guid.NewGuid(),
                                UserId           = NopContext.Current.User.CustomerId,
                                TopicId          = forumTopic.ForumTopicId,
                                CreatedOn        = nowDT
                            };

                            this.ForumService.InsertSubscription(forumSubscription);
                        }
                    }

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

                    if (!this.ForumService.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"));
                    }

                    //forum topic
                    forumTopic.TopicTypeId = (int)topicType;
                    forumTopic.Subject     = subject;
                    forumTopic.UpdatedOn   = nowDT;
                    this.ForumService.UpdateTopic(forumTopic);

                    //forum post
                    var firstPost = forumTopic.FirstPost;
                    if (firstPost != null)
                    {
                        firstPost.Text      = text;
                        firstPost.UpdatedOn = nowDT;
                        this.ForumService.UpdatePost(firstPost);
                    }
                    else
                    {
                        //error (not possible)
                        firstPost = new ForumPost()
                        {
                            TopicId   = forumTopic.ForumTopicId,
                            UserId    = forumTopic.UserId,
                            Text      = text,
                            IPAddress = IPAddress,
                            UpdatedOn = nowDT
                        };

                        this.ForumService.InsertPost(firstPost, false);
                    }

                    //subscription
                    if (this.ForumService.IsUserAllowedToSubscribe(NopContext.Current.User))
                    {
                        var forumSubscription = this.ForumService.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                                      0, forumTopic.ForumTopicId, 0, 1).FirstOrDefault();
                        if (subscribe)
                        {
                            if (forumSubscription == null)
                            {
                                forumSubscription = new ForumSubscription()
                                {
                                    SubscriptionGuid = Guid.NewGuid(),
                                    UserId           = NopContext.Current.User.CustomerId,
                                    TopicId          = forumTopic.ForumTopicId,
                                    CreatedOn        = nowDT
                                };

                                this.ForumService.InsertSubscription(forumSubscription);
                            }
                        }
                        else
                        {
                            if (forumSubscription != null)
                            {
                                this.ForumService.DeleteSubscription(forumSubscription.ForumSubscriptionId);
                            }
                        }
                    }

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

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

                    //forum post
                    var forumPost = new ForumPost()
                    {
                        TopicId   = this.ForumTopicId,
                        UserId    = NopContext.Current.User.CustomerId,
                        Text      = text,
                        IPAddress = IPAddress,
                        CreatedOn = nowDT,
                        UpdatedOn = nowDT
                    };
                    this.ForumService.InsertPost(forumPost, true);

                    //subscription
                    if (this.ForumService.IsUserAllowedToSubscribe(NopContext.Current.User))
                    {
                        var forumSubscription = this.ForumService.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                                      0, forumPost.TopicId, 0, 1).FirstOrDefault();
                        if (subscribe)
                        {
                            if (forumSubscription == null)
                            {
                                forumSubscription = new ForumSubscription()
                                {
                                    SubscriptionGuid = Guid.NewGuid(),
                                    UserId           = NopContext.Current.User.CustomerId,
                                    TopicId          = forumPost.TopicId,
                                    CreatedOn        = nowDT
                                };

                                this.ForumService.InsertSubscription(forumSubscription);
                            }
                        }
                        else
                        {
                            if (forumSubscription != null)
                            {
                                this.ForumService.DeleteSubscription(forumSubscription.ForumSubscriptionId);
                            }
                        }
                    }


                    int pageSize = 10;
                    if (this.ForumService.PostsPageSize > 0)
                    {
                        pageSize = this.ForumService.PostsPageSize;
                    }
                    int    pageIndex = this.ForumService.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 = this.ForumService.GetPostById(this.ForumPostId);
                    if (forumPost == null)
                    {
                        Response.Redirect(SEOHelper.GetForumMainUrl());
                    }

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

                    forumPost.Text      = text;
                    forumPost.UpdatedOn = nowDT;
                    this.ForumService.UpdatePost(forumPost);

                    //subscription
                    if (this.ForumService.IsUserAllowedToSubscribe(NopContext.Current.User))
                    {
                        var forumSubscription = this.ForumService.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                                      0, forumPost.TopicId, 0, 1).FirstOrDefault();
                        if (subscribe)
                        {
                            if (forumSubscription == null)
                            {
                                forumSubscription = new ForumSubscription()
                                {
                                    SubscriptionGuid = Guid.NewGuid(),
                                    UserId           = NopContext.Current.User.CustomerId,
                                    TopicId          = forumPost.TopicId,
                                    CreatedOn        = nowDT
                                };

                                this.ForumService.InsertSubscription(forumSubscription);
                            }
                        }
                        else
                        {
                            if (forumSubscription != null)
                            {
                                this.ForumService.DeleteSubscription(forumSubscription.ForumSubscriptionId);
                            }
                        }
                    }

                    int pageSize = 10;
                    if (this.ForumService.PostsPageSize > 0)
                    {
                        pageSize = this.ForumService.PostsPageSize;
                    }
                    int    pageIndex = this.ForumService.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);
            }
        }
コード例 #9
0
ファイル: ForumPostEdit.ascx.cs プロジェクト: terry2012/DSV
 protected void btnCancel_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.AddTopic)
         {
             var forum = ForumManager.GetForumById(this.ForumId);
             if (forum != null)
             {
                 string forumUrl = SEOHelper.GetForumUrl(forum);
                 Response.Redirect(forumUrl);
             }
             else
             {
                 Response.Redirect(SEOHelper.GetForumMainUrl());
             }
         }
         else if (this.EditTopic)
         {
             var forumTopic = ForumManager.GetTopicById(this.ForumTopicId);
             if (forumTopic != null)
             {
                 string topicUrl = SEOHelper.GetForumTopicUrl(forumTopic);
                 Response.Redirect(topicUrl);
             }
             else
             {
                 Response.Redirect(SEOHelper.GetForumMainUrl());
             }
         }
         else if (this.AddPost)
         {
             var forumTopic = ForumManager.GetTopicById(this.ForumTopicId);
             if (forumTopic != null)
             {
                 string topicUrl = SEOHelper.GetForumTopicUrl(forumTopic);
                 Response.Redirect(topicUrl);
             }
             else
             {
                 Response.Redirect(SEOHelper.GetForumMainUrl());
             }
         }
         else if (this.EditPost)
         {
             var forumPost = ForumManager.GetPostById(this.ForumPostId);
             if (forumPost != null)
             {
                 string topicUrl = SEOHelper.GetForumTopicUrl(forumPost.TopicId);
                 Response.Redirect(topicUrl);
             }
             else
             {
                 Response.Redirect(SEOHelper.GetForumMainUrl());
             }
         }
     }
     catch (Exception exc)
     {
         pnlError.Visible   = true;
         lErrorMessage.Text = Server.HtmlEncode(exc.Message);
     }
 }
コード例 #10
0
        private void BindData()
        {
            var forumTopic = this.ForumService.GetTopicById(this.TopicId, true);

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

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

                int pageSize = 10;
                if (this.ForumService.PostsPageSize > 0)
                {
                    pageSize = this.ForumService.PostsPageSize;
                }

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

                    this.postsPager2.PageSize     = pageSize;
                    this.postsPager2.TotalRecords = forumPosts.TotalCount;
                    this.postsPager2.PageIndex    = this.CurrentPageIndex;

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

                //subsciption
                if (this.ForumService.IsUserAllowedToSubscribe(NopContext.Current.User))
                {
                    var forumSubscription = this.ForumService.GetAllSubscriptions(NopContext.Current.User.CustomerId,
                                                                                  0, forumTopic.ForumTopicId, 0, 1).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());
            }
        }