public AjaxResponse DoStickyTopic(int idTopic, Guid settingsID) { _forumManager = ForumManager.GetForumManager(settingsID); var resp = new AjaxResponse(); resp.rs2 = idTopic.ToString(); var topic = ForumDataProvider.GetTopicByID(TenantProvider.CurrentTenantID, idTopic); if (topic == null) { resp.rs1 = "0"; resp.rs3 = Resources.ForumUCResource.ErrorAccessDenied; return(resp); } if (!_forumManager.ValidateAccessSecurityAction(ForumAction.TopicSticky, topic)) { resp.rs1 = "0"; resp.rs3 = Resources.ForumUCResource.ErrorAccessDenied; return(resp); } topic.Sticky = !topic.Sticky; try { ForumDataProvider.UpdateTopic(TenantProvider.CurrentTenantID, topic.ID, topic.Title, topic.Sticky, topic.Closed); resp.rs1 = "1"; if (topic.Sticky) { resp.rs3 = Resources.ForumUCResource.SuccessfullyStickyTopicMessage; } else { resp.rs3 = Resources.ForumUCResource.SuccessfullyClearStickyTopicMessage; } var settings = ForumManager.GetSettings(settingsID); if (settings != null && settings.ActivityPublisher != null) { settings.ActivityPublisher.TopicSticky(topic); } } catch (Exception e) { resp.rs1 = "0"; resp.rs3 = HttpUtility.HtmlEncode(e.Message); } return(resp); }
public AjaxResponse DoCloseTopic(int idTopic, Guid settingsID) { _forumManager = Community.Forum.ForumManager.Settings.ForumManager; var resp = new AjaxResponse { rs2 = idTopic.ToString() }; var topic = ForumDataProvider.GetTopicByID(TenantProvider.CurrentTenantID, idTopic); if (topic == null) { resp.rs1 = "0"; resp.rs3 = Resources.ForumUCResource.ErrorAccessDenied; return(resp); } if (!_forumManager.ValidateAccessSecurityAction(ForumAction.TopicClose, topic)) { resp.rs1 = "0"; resp.rs3 = Resources.ForumUCResource.ErrorAccessDenied; return(resp); } topic.Closed = !topic.Closed; try { ForumDataProvider.UpdateTopic(TenantProvider.CurrentTenantID, topic.ID, topic.Title, topic.Sticky, topic.Closed); resp.rs1 = "1"; resp.rs3 = topic.Closed ? Resources.ForumUCResource.SuccessfullyCloseTopicMessage : Resources.ForumUCResource.SuccessfullyOpenTopicMessage; resp.rs4 = topic.Closed ? Resources.ForumUCResource.OpenTopicButton : Resources.ForumUCResource.CloseTopicButton; resp.status = topic.Closed ? "close" : "open"; } catch (Exception e) { resp.rs1 = "0"; resp.rs3 = HttpUtility.HtmlEncode(e.Message); } return(resp); }
protected void Page_Load(object sender, EventArgs e) { _settings = Community.Forum.ForumManager.Settings; _forumManager = _settings.ForumManager; Utility.RegisterTypeForAjax(typeof(TagSuggest)); _subject = ""; int idTopic = 0; if (!String.IsNullOrEmpty(Request[_settings.TopicParamName])) { try { idTopic = Convert.ToInt32(Request[_settings.TopicParamName]); } catch { idTopic = 0; } } if (idTopic == 0) { Response.Redirect(_forumManager.PreviousPage.Url); return; } topicId = idTopic; EditableTopic = ForumDataProvider.GetTopicByID(TenantProvider.CurrentTenantID, idTopic); if (EditableTopic == null) { Response.Redirect(_forumManager.PreviousPage.Url); return; } if (!_forumManager.ValidateAccessSecurityAction(ForumAction.TopicEdit, EditableTopic)) { Response.Redirect(_forumManager.PreviousPage.Url); return; } _subject = EditableTopic.Title; _tagString = String.Join(",", EditableTopic.Tags.Select(x => x.Name)); _tagValues = JsonConvert.SerializeObject(EditableTopic.Tags.Select(x => new List <object> { x.Name, x.ID })); if (EditableTopic.Type == TopicType.Informational) { _pollMaster.Visible = false; } else { _pollMaster.QuestionFieldID = "forum_subject"; if (IsPostBack == false) { var question = ForumDataProvider.GetPollByID(TenantProvider.CurrentTenantID, EditableTopic.QuestionID); _pollMaster.Singleton = (question.Type == QuestionType.OneAnswer); _pollMaster.Name = question.Name; _pollMaster.ID = question.ID.ToString(); foreach (var variant in question.AnswerVariants) { _pollMaster.AnswerVariants.Add(new PollFormMaster.AnswerViarint() { ID = variant.ID.ToString(), Name = variant.Name }); } } } #region IsPostBack if (IsPostBack) { if (EditableTopic.Type == TopicType.Informational) { _subject = Request["forum_subject"].Trim(); } else { _subject = (_pollMaster.Name ?? "").Trim(); } if (String.IsNullOrEmpty(_subject)) { _subject = ""; _errorMessage = "<div class=\"errorBox\">" + Resources.ForumUCResource.ErrorSubjectEmpty + "</div>"; return; } if (EditableTopic.Type == TopicType.Poll && _pollMaster.AnswerVariants.Count < 2) { _errorMessage = "<div class=\"errorBox\">" + Resources.ForumUCResource.ErrorPollVariantCount + "</div>"; return; } if (!String.IsNullOrEmpty(Request["forum_tags"])) { _tagString = Request["forum_tags"].Trim(); } else { _tagString = ""; } if (!String.IsNullOrEmpty(Request["forum_search_tags"])) { _tagValues = Request["forum_search_tags"].Trim(); } EditableTopic.Title = _subject; if (_forumManager.ValidateAccessSecurityAction(ForumAction.TagCreate, new Thread() { ID = EditableTopic.ThreadID })) { var removeTags = EditableTopic.Tags; EditableTopic.Tags = CreateTags(); removeTags.RemoveAll(t => EditableTopic.Tags.Find(nt => nt.ID == t.ID) != null); foreach (var tag in EditableTopic.Tags) { if (tag.ID == 0) { ForumDataProvider.CreateTag(TenantProvider.CurrentTenantID, EditableTopic.ID, tag.Name, tag.IsApproved); } else { ForumDataProvider.AttachTagToTopic(TenantProvider.CurrentTenantID, tag.ID, EditableTopic.ID); } } removeTags.ForEach(t => { ForumDataProvider.RemoveTagFromTopic(TenantProvider.CurrentTenantID, t.ID, EditableTopic.ID); }); } try { if (EditableTopic.Type == TopicType.Poll) { List <AnswerVariant> variants = new List <AnswerVariant>(); int i = 1; foreach (var answVariant in _pollMaster.AnswerVariants) { variants.Add(new AnswerVariant() { ID = (String.IsNullOrEmpty(answVariant.ID) ? 0 : Convert.ToInt32(answVariant.ID)), Name = answVariant.Name, SortOrder = i - 1 }); i++; } ForumDataProvider.UpdatePoll(TenantProvider.CurrentTenantID, EditableTopic.QuestionID, _pollMaster.Singleton ? QuestionType.OneAnswer : QuestionType.SeveralAnswer, EditableTopic.Title, variants); } ForumDataProvider.UpdateTopic(TenantProvider.CurrentTenantID, EditableTopic.ID, EditableTopic.Title, EditableTopic.Sticky, EditableTopic.Closed); FactoryIndexer <TopicWrapper> .UpdateAsync(EditableTopic); _errorMessage = "<div class=\"okBox\">" + Resources.ForumUCResource.SuccessfullyEditTopicMessage + "</div>"; Response.Redirect(_forumManager.PreviousPage.Url); } catch (Exception ex) { _errorMessage = "<div class=\"errorBox\">" + ex.Message.HtmlEncode() + "</div>"; return; } } #endregion }
public ForumTopicWrapperFull UpdateTopic(int topicid, string subject, bool sticky, bool closed) { ForumDataProvider.UpdateTopic(TenantId, topicid, subject, sticky, closed); return(GetTopicPosts(topicid)); }