public void Add(string input) { if (string.IsNullOrEmpty(input)) { throw new ArgumentException(); } var word = new NegativeWord(input.ToLowerInvariant()); //no duplicates var exists = _negativeWordsRepository.Exists(word); if (!exists) { _negativeWordsRepository.Add(word); } }
public static void Main(string[] args) { //Dependency Injection _negativeWordRepository = new NegativeWordsRepository(); _negativeWordService = new NegativeWordsService(_negativeWordRepository); //Seed data _negativeWordRepository.Add(new NegativeWord("nasty")); _negativeWordRepository.Add(new NegativeWord("bad")); _negativeWordRepository.Add(new NegativeWord("horrible")); _negativeWordRepository.Add(new NegativeWord("swine")); var input = string.Empty; do { Console.Clear(); Console.WriteLine("Press the corresponding key and return"); Console.WriteLine(); Console.WriteLine("1 - Count Negative Words In A Text"); Console.WriteLine("2 - List Negative Words"); Console.WriteLine("3 - Add Negative Word"); Console.WriteLine("4 - Remove Negative Word"); Console.WriteLine("5 - Filter On"); Console.WriteLine("6 - Filter Off"); Console.WriteLine("X - Exit"); Console.WriteLine(); input = Console.ReadLine() ?? ""; switch (input) { case "1": { Console.Clear(); CountNegativeWords(); break; } case "2": { Console.Clear(); ListNegativeWords(); break; } case "3": { Console.Clear(); AddNegativeWords(); break; } case "4": { Console.Clear(); RemoveNegativeWords(); break; } case "5": { Console.Clear(); FilterOn(); break; } case "6": { Console.Clear(); FilterOff(); break; } default: { Console.WriteLine("Input not recognized. Please try again."); break; } } } while (input.ToLower() != "x"); }