protected string GetForumTopicInfo(ForumSubscription subscription)
        {
            if (subscription == null)
            {
                return String.Empty;
            }

            Forum forum = subscription.Forum;
            if (forum != null)
            {
                return Server.HtmlEncode(forum.Name);
            }

            ForumTopic topic = subscription.Topic;
            if (topic != null)
            {
                return Server.HtmlEncode(topic.Subject);
            }

            return String.Empty;
        }
        protected string GetForumTopicLink(ForumSubscription subscription)
        {
            if (subscription == null)
            {
                return String.Empty;
            }

            Forum forum = subscription.Forum;
            if (forum != null)
            {
                return SEOHelper.GetForumUrl(forum);
            }

            ForumTopic topic = subscription.Topic;
            if (topic != null)
            {
                return SEOHelper.GetForumTopicUrl(topic);
            }

            return String.Empty;
        }
示例#3
0
        private static ForumSubscription DBMapping(DBForumSubscription dbItem)
        {
            if (dbItem == null)
                return null;

            ForumSubscription item = new ForumSubscription();
            item.ForumSubscriptionID = dbItem.ForumSubscriptionID;
            item.SubscriptionGUID = dbItem.SubscriptionGUID;
            item.UserID = dbItem.UserID;
            item.ForumID = dbItem.ForumID;
            item.TopicID = dbItem.TopicID;
            item.CreatedOn = dbItem.CreatedOn;

            return item;
        }
示例#4
0
        /// <summary>
        /// Updates the forum subscription
        /// </summary>
        /// <param name="forumSubscription">Forum subscription</param>
        public void UpdateSubscription(ForumSubscription forumSubscription)
        {
            if (forumSubscription == null)
                throw new ArgumentNullException("forumSubscription");

            if (!_context.IsAttached(forumSubscription))
                _context.ForumSubscriptions.Attach(forumSubscription);

            _context.SaveChanges();
        }
示例#5
0
        /// <summary>
        /// Inserts a forum subscription
        /// </summary>
        /// <param name="forumSubscription">Forum subscription</param>
        public void InsertSubscription(ForumSubscription forumSubscription)
        {
            if (forumSubscription == null)
                throw new ArgumentNullException("forumSubscription");

            _context.ForumSubscriptions.AddObject(forumSubscription);
            _context.SaveChanges();
        }
        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);
            }
        }