protected void btnDelete_Click(object sender, EventArgs e) { int forumPostID = 0; int.TryParse(lblForumPostID.Text, out forumPostID); ForumPost forumPost = ForumManager.GetPostByID(forumPostID); if (forumPost != null) { ForumTopic forumTopic = forumPost.Topic; if (!ForumManager.IsUserAllowedToDeletePost(NopContext.Current.User, forumPost)) { string loginURL = CommonHelper.GetLoginPageURL(true); Response.Redirect(loginURL); } ForumManager.DeletePost(forumPost.ForumPostID); string url = string.Empty; if (forumTopic != null) { url = SEOHelper.GetForumTopicURL(forumTopic.ForumTopicID); } else { url = SEOHelper.GetForumMainURL(); } Response.Redirect(url); } }
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); } }