Example #1
0
    /// <summary>
    /// Gets and updates the first single bad word matching the condition. Called when the "Get and update bad word" button is pressed.
    /// Expects the CreateBadWord method to be run first.
    /// </summary>
    private bool GetAndUpdateBadWord()
    {
        // Prepare the parameters
        string where = "[WordExpression] = 'testbadword'";

        // Get the data
        DataSet words = BadWordInfoProvider.GetBadWords(where, null);

        if (!DataHelper.DataSourceIsEmpty(words))
        {
            // Get the bad word's data row
            DataRow wordDr = words.Tables[0].Rows[0];

            // Create object from DataRow
            BadWordInfo modifyWord = new BadWordInfo(wordDr);

            // Update the properties
            modifyWord.WordAction      = BadWordActionEnum.Replace;
            modifyWord.WordReplacement = "testpoliteword";

            // Save the changes
            BadWordInfoProvider.SetBadWordInfo(modifyWord);

            return(true);
        }

        return(false);
    }
Example #2
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string errorMessage = new Validator().NotEmpty(txtWordExpression.Text, GetString("general.requiresvalue")).Result;

        if (errorMessage == string.Empty)
        {
            if (badWordObj == null)
            {
                badWordObj = new BadWordInfo();
            }

            // Set edited object
            EditedObject = badWordObj;

            // If bad word doesn't already exist, create new one
            if (!(((badWordId <= 0) || WordExpressionHasChanged()) && BadWordInfoProvider.BadWordExists(txtWordExpression.Text.Trim())))
            {
                badWordObj.WordExpression = txtWordExpression.Text.Trim();
                BadWordActionEnum action =
                    (BadWordActionEnum)Convert.ToInt32(SelectBadWordActionControl.Value.ToString().Trim());
                badWordObj.WordAction              = !chkInheritAction.Checked ? action : 0;
                badWordObj.WordReplacement         = (!chkInheritReplacement.Checked && (action == BadWordActionEnum.Replace)) ? txtWordReplacement.Text : null;
                badWordObj.WordLastModified        = DateTime.Now;
                badWordObj.WordIsRegularExpression = chkIsRegular.Checked;
                badWordObj.WordMatchWholeWord      = chkMatchWholeWord.Checked;

                if (badWordId <= 0)
                {
                    badWordObj.WordIsGlobal = true;
                }

                BadWordInfoProvider.SetBadWordInfo(badWordObj);

                if (badWordId <= 0)
                {
                    string redirectTo = badWordId <= 0 ? UIContextHelper.GetElementUrl("CMS.Badwords", "Administration.BadWords.Edit") : UIContextHelper.GetElementUrl("CMS.Badwords", "Administration.BadWords.Edit.General");
                    redirectTo = URLHelper.AddParameterToUrl(redirectTo, "objectid", badWordObj.WordID.ToString());
                    redirectTo = URLHelper.AddParameterToUrl(redirectTo, "saved", "1");
                    URLHelper.Redirect(redirectTo);
                }
                else
                {
                    ScriptHelper.RefreshTabHeader(Page, txtWordExpression.Text.Trim());
                    ShowChangesSaved();
                }
            }
            else
            {
                ShowError(GetString("badwords_edit.badwordexists"));
            }
        }
        else
        {
            ShowError(errorMessage);
        }
    }
 protected void isGlobal_CheckedChanged(object sender, EventArgs e)
 {
     if (badWordObj != null)
     {
         // Set whether the word is global
         badWordObj.WordIsGlobal = radAll.Checked;
         // Save badword
         BadWordInfoProvider.SetBadWordInfo(badWordObj);
         // Display message
         ShowChangesSaved();
         // Show / hide selector
         SetSelectorVisibility();
     }
 }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string errorMessage = new Validator().NotEmpty(txtWordExpression.Text, GetString("general.requiresvalue")).Result;

        if (errorMessage == string.Empty)
        {
            if (badWordObj == null)
            {
                badWordObj = new BadWordInfo();
            }

            // Set edited object
            EditedObject = badWordObj;

            // If bad word doesn't already exist, create new one
            if (!BadWordInfoProvider.BadWordExists(txtWordExpression.Text.Trim()) || (badWordId != 0))
            {
                badWordObj.WordExpression = txtWordExpression.Text.Trim();
                BadWordActionEnum action =
                    (BadWordActionEnum)Convert.ToInt32(SelectBadWordActionControl.Value.ToString().Trim());
                badWordObj.WordAction              = !chkInheritAction.Checked ? action : 0;
                badWordObj.WordReplacement         = (!chkInheritReplacement.Checked && (action == BadWordActionEnum.Replace)) ? txtWordReplacement.Text : null;
                badWordObj.WordLastModified        = DateTime.Now;
                badWordObj.WordIsRegularExpression = chkIsRegular.Checked;
                badWordObj.WordMatchWholeWord      = chkMatchWholeWord.Checked;

                if (badWordId == 0)
                {
                    badWordObj.WordIsGlobal = true;
                }

                BadWordInfoProvider.SetBadWordInfo(badWordObj);
                string redirectTo = badWordId == 0 ? "BadWords_Edit.aspx" : "BadWords_Edit_General.aspx";

                URLHelper.Redirect(redirectTo + "?badwordid=" + Convert.ToString(badWordObj.WordID) + "&saved=1");
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = GetString("badwords_edit.badwordexists");
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }
Example #5
0
    /// <summary>
    /// Creates a "testbadword" bad word. Called when the "Create word" button is pressed.
    /// </summary>
    private bool CreateBadWord()
    {
        // Create new bad word object
        BadWordInfo newWord = new BadWordInfo();

        // Set the properties
        newWord.WordExpression          = "testbadword";
        newWord.WordAction              = BadWordActionEnum.ReportAbuse;
        newWord.WordIsGlobal            = true;
        newWord.WordIsRegularExpression = false;

        // Save the bad word
        BadWordInfoProvider.SetBadWordInfo(newWord);

        return(true);
    }