/// <summary> /// The is input verified. /// </summary> /// <returns> /// Return if input is verified. /// </returns> protected bool IsInputVerified() { if (ObjectExtensions.ToType <int>(this.PollGroupListDropDown.SelectedIndex) <= 0) { if (this.Question.Text.Trim().Length == 0) { YafContext.Current.AddLoadMessage(this.GetText("POLLEDIT", "NEED_QUESTION")); return(false); } this.Question.Text = HtmlHelper.StripHtml(this.Question.Text); int notNullcount = (from RepeaterItem ri in this.ChoiceRepeater.Items select((TextBox)ri.FindControl("PollChoice")).Text.Trim()).Count( value => !string.IsNullOrEmpty(value)); if (notNullcount < 2) { YafContext.Current.AddLoadMessage(this.GetText("POLLEDIT", "NEED_CHOICES")); return(false); } int dateVerified; if (!int.TryParse(this.PollExpire.Text.Trim(), out dateVerified) && StringExtensions.IsSet(this.PollExpire.Text.Trim())) { YafContext.Current.AddLoadMessage(this.GetText("POLLEDIT", "EXPIRE_BAD")); return(false); } // Set default value if (StringExtensions.IsNotSet(this.PollExpire.Text.Trim()) && this.IsClosedBoundCheckBox.Checked) { this.PollExpire.Text = "1"; } } return(true); }
/// <summary> /// The get poll id. /// </summary> /// <returns> /// Returns the Poll Id /// </returns> private bool?GetPollID() { if (int.TryParse(this.PollExpire.Text.Trim(), out this._daysPollExpire)) { this._datePollExpire = DateTime.UtcNow.AddDays(this._daysPollExpire); } // we are just using existing poll if (this.PollId != null) { string questionPath = this.QuestionObjectPath.Text.Trim(); string questionMime = string.Empty; if (StringExtensions.IsSet(questionPath)) { long length; questionMime = ImageHelper.GetImageParameters(new Uri(questionPath), out length); if (StringExtensions.IsNotSet(questionMime)) { YafContext.Current.AddLoadMessage(this.GetTextFormatted("POLLIMAGE_INVALID", questionPath)); return(false); } if (length > this.Get <YafBoardSettings>().PollImageMaxFileSize * 1024) { YafContext.Current.AddLoadMessage( this.GetTextFormatted( "POLLIMAGE_TOOBIG", length / 1024, this.Get <YafBoardSettings>().PollImageMaxFileSize, questionPath)); return(false); } } LegacyDb.poll_update( this.PollId, this.Question.Text, this._datePollExpire, this.IsBoundCheckBox.Checked, this.IsClosedBoundCheckBox.Checked, this.AllowMultipleChoicesCheckBox.Checked, this.ShowVotersCheckBox.Checked, this.AllowSkipVoteCheckBox.Checked, questionPath, questionMime); foreach (RepeaterItem ri in this.ChoiceRepeater.Items) { string choice = ((TextBox)ri.FindControl("PollChoice")).Text.Trim(); string chid = ((HiddenField)ri.FindControl("PollChoiceID")).Value; string choiceObjectPath = ((TextBox)ri.FindControl("ObjectPath")).Text.Trim(); string choiceImageMime = string.Empty; // update choice if (StringExtensions.IsSet(choiceObjectPath)) { long length; choiceImageMime = ImageHelper.GetImageParameters(new Uri(choiceObjectPath), out length); if (StringExtensions.IsNotSet(choiceImageMime)) { YafContext.Current.AddLoadMessage( this.GetTextFormatted("POLLIMAGE_INVALID", choiceObjectPath.Trim())); return(false); } if (length > this.Get <YafBoardSettings>().PollImageMaxFileSize * 1024) { YafContext.Current.AddLoadMessage( this.GetTextFormatted( "POLLIMAGE_TOOBIG", length / 1024, this.Get <YafBoardSettings>().PollImageMaxFileSize, choiceObjectPath)); return(false); } } if (string.IsNullOrEmpty(chid) && !string.IsNullOrEmpty(choice)) { // add choice LegacyDb.choice_add(this.PollId, choice, choiceObjectPath, choiceImageMime); } else if (!string.IsNullOrEmpty(chid) && !string.IsNullOrEmpty(choice)) { LegacyDb.choice_update(chid, choice, choiceObjectPath, choiceImageMime); } else if (!string.IsNullOrEmpty(chid) && string.IsNullOrEmpty(choice)) { // remove choice LegacyDb.choice_delete(chid); } } return(true); } else { // User wishes to create a poll // The value was selected, we attach an existing poll if (ObjectExtensions.ToType <int>(this.PollGroupListDropDown.SelectedIndex) > 0) { int result = LegacyDb.pollgroup_attach( ObjectExtensions.ToType <int>(this.PollGroupListDropDown.SelectedValue), this._topicId, this._forumId, this._categoryId, this._boardId); if (result == 1) { this.PageContext.AddLoadMessage(this.GetText("POLLEDIT", "POLLGROUP_ATTACHED")); } return(true); } string questionPath = this.QuestionObjectPath.Text.Trim(); string questionMime = string.Empty; if (StringExtensions.IsSet(questionPath)) { long length; questionMime = ImageHelper.GetImageParameters(new Uri(questionPath), out length); if (StringExtensions.IsNotSet(questionMime)) { YafContext.Current.AddLoadMessage( this.GetTextFormatted("POLLIMAGE_INVALID", this.QuestionObjectPath.Text.Trim())); return(false); } if (length > this.Get <YafBoardSettings>().PollImageMaxFileSize * 1024) { YafContext.Current.AddLoadMessage( this.GetTextFormatted( "POLLIMAGE_TOOBIG", length / 1024, this.Get <YafBoardSettings>().PollImageMaxFileSize, questionPath)); } } var pollSaveList = new List <PollSaveList>(); var rawChoices = new string[3, this.ChoiceRepeater.Items.Count]; int j = 0; foreach (RepeaterItem ri in this.ChoiceRepeater.Items) { string choiceObjectPath = ((TextBox)ri.FindControl("ObjectPath")).Text.Trim(); string choiceObjectMime = string.Empty; if (StringExtensions.IsSet(choiceObjectPath)) { long length; choiceObjectMime = ImageHelper.GetImageParameters(new Uri(choiceObjectPath), out length); if (StringExtensions.IsNotSet(choiceObjectMime)) { YafContext.Current.AddLoadMessage( this.GetTextFormatted("POLLIMAGE_INVALID", choiceObjectPath.Trim())); return(false); } if (length > this.Get <YafBoardSettings>().PollImageMaxFileSize * 1024) { YafContext.Current.AddLoadMessage( this.GetTextFormatted( "POLLIMAGE_TOOBIG", length / 1024, this.Get <YafBoardSettings>().PollImageMaxFileSize, choiceObjectPath)); return(false); } } rawChoices[0, j] = HtmlHelper.StripHtml(((TextBox)ri.FindControl("PollChoice")).Text.Trim()); rawChoices[1, j] = choiceObjectPath; rawChoices[2, j] = choiceObjectMime; j++; } int?realTopic = this._topicId; if (this._topicId == null) { realTopic = this._editTopicId; } if (this._datePollExpire == null && StringExtensions.IsSet(this.PollExpire.Text.Trim())) { this._datePollExpire = DateTime.UtcNow.AddDays(ObjectExtensions.ToType <int>(this.PollExpire.Text.Trim())); } pollSaveList.Add( new PollSaveList( this.Question.Text, rawChoices, this._datePollExpire, this.PageContext.PageUserID, realTopic, this._forumId, this._categoryId, this._boardId, questionPath, questionMime, this.IsBoundCheckBox.Checked, this.IsClosedBoundCheckBox.Checked, this.AllowMultipleChoicesCheckBox.Checked, this.ShowVotersCheckBox.Checked, this.AllowSkipVoteCheckBox.Checked)); LegacyDb.poll_save(pollSaveList); return(true); } return(false); // A poll was not created for this topic. }