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 }