|
||
|
API examples for newer versions Please visit the latest API Examples documentation to view API examples for newer versions of Kentico. |
The following example creates a bad word.
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; } |
The following example gets and updates the bad word created by the code example above.
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; } |
The following example gets and bulk updates multiple bad words selected from database based on a WHERE condition.
private bool GetAndBulkUpdateBadWords() { // Prepare the parameters string where = "[WordExpression] = 'testbadword'";
// Get the data DataSet words = BadWordInfoProvider.GetBadWords(where, null); if (!DataHelper.DataSourceIsEmpty(words)) { // Loop through the individual items foreach (DataRow wordDr in words.Tables[0].Rows) { // 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; } |
The following example deletes the bad word created by the first code example on this page.
private bool DeleteBadWord() { // Prepare the parameters string where = "[WordExpression] = 'testbadword' ";
// Get the data DataSet words = BadWordInfoProvider.GetBadWords(where, null);
if (!DataHelper.DataSourceIsEmpty(words)) { foreach (DataRow wordDr in words.Tables[0].Rows) { // Create object from DataRow BadWordInfo deleteWord = new BadWordInfo(wordDr);
// Delete the bad word BadWordInfoProvider.DeleteBadWordInfo(deleteWord); }
return true; }
return false; } |