public virtual BadWord UpdateBadWord(BadWord entity) { if (entity.IsTransient()) { return(entity); } BadWord other = GetBadWord(entity.BadWordId); if (entity.Equals(other)) { return(entity); } string sql = @"Update BadWord set [LocaleSetting]=@LocaleSetting , [Word]=@Word , [CreatedOn]=@CreatedOn where BadWordID=@BadWordID" ; SqlParameter[] parameterArray = new SqlParameter[] { new SqlParameter("@BadWordID", entity.BadWordId) , new SqlParameter("@LocaleSetting", entity.LocaleSetting) , new SqlParameter("@Word", entity.Word) , new SqlParameter("@CreatedOn", entity.CreatedOn) }; SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray); return(GetBadWord(entity.BadWordId)); }
public static (BadWord word, int?pos) CheckForBadWords(this string message, BadWord[] badWords) { if (badWords?.Length is null or 0) { return(null, null); } //Checks for bad words var sb = new StringBuilder(message.Length); foreach (char c in message) { switch (c) { case '': //zero width unicode needs to be removed break; case '@': case '4': sb.Append('a'); break; case '¢': sb.Append('c'); break; case '3': sb.Append('e'); break; case '1': case '!': sb.Append('i'); break; case '0': sb.Append('o'); break; case '5': case '$': sb.Append('s'); break; default: if (!char.IsPunctuation(c) && !char.IsSymbol(c)) { sb.Append(c); } break; } } string strippedMessage = sb.ToString(); //splits string into words separated the splitter characters string[] messageParts = message.Split(splitters, StringSplitOptions.RemoveEmptyEntries); foreach (BadWord badWord in badWords) { if (badWord.PartOfWord) { //Need to override index system here since we strip characters int index = strippedMessage.IndexOf(badWord.Word, StringComparison.InvariantCultureIgnoreCase); if (index > -1) { try { string filtered = strippedMessage.Substring(index, badWord.Word.Length); //Filtered text doesn't have to equal explicit word because of substitute characters index = message.IndexOf(filtered, StringComparison.InvariantCultureIgnoreCase); return(badWord, index); } catch (IndexOutOfRangeException e) { #if DEBUG throw; #endif new LogMessage(LogSeverity.Error, "Filter", "Highlight failed in filter", e).Log(); return(badWord, null); } } } else //When bad word is ignored inside of words { foreach (string word in messageParts) //Then we go through and check if each word equals the bad word { if (word.Equals(badWord.Word, StringComparison.InvariantCultureIgnoreCase)) { return(badWord, null); } } } } return(null, null); }