Exemplo n.º 1
0
 private static void DisplayCommand(Dictionary dict)
 {
     foreach (var word in dict)
     {
         Console.WriteLine(word);
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Dictionary dictionary = new Dictionary("mongodb://localhost//");

            dictionary.AddWord(new Word("JSON", "Jason Jekov"));
            foreach (var word in dictionary.ListWords())
            {
                Console.WriteLine("Word: {0}, Translation: {1}", word.Name, word.Translation);
            }
            var trans = dictionary.FindWord("Pesho");
            Console.WriteLine("Pesho: {0}", trans);


        }
Exemplo n.º 3
0
        private static void RemoveCommand(Dictionary dict)
        {
            Console.WriteLine("Please enter the word to remove:");
            var word = Console.ReadLine();

            var removeResult = dict.Remove(word);

            if (removeResult)
            {
                Console.WriteLine("Removed the word.");
            }
            else
            {
                Console.WriteLine("Word not found in the dictionary.");
            }
        }
Exemplo n.º 4
0
        private static void AddCommand(Dictionary dict)
        {
            Console.WriteLine("Please enter the word:");
            var word = Console.ReadLine();
            Console.WriteLine("Please enter the explanation:");
            var explanation = Console.ReadLine();
            var addResult = dict.Add(word, explanation);

            if (addResult)
            {
                Console.WriteLine("Successfully added!");
            }
            else
            {
                Console.WriteLine("This word already exists in the dictionary.");
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            string connectionString = "mongodb://localhost";
            var client = new MongoClient(connectionString);
            var server = client.GetServer();
            var db = server.GetDatabase("Dictionary");
            MongoCollection<Word> dictionary = db.GetCollection<Word>("Dictionary");

            Dictionary dict = new Dictionary(dictionary);

            Console.WriteLine("Welcome to MongoDb Dictionary");

            string userCommand = "";
            while (userCommand != "exit")
            {
                Console.WriteLine("Enter 'add' to enter new word");
                Console.WriteLine("Enter 'show' to display all entries");
                Console.WriteLine("Enter 'remove' to remove  word");
                Console.WriteLine("Enter 'exit' to exit");

                userCommand = Console.ReadLine();

                dict.Add("test", "a test entry");

                switch (userCommand)
                {
                    case "add":
                        AddCommand(dict);
                        break;
                    case "show":
                        DisplayCommand(dict);
                        break;
                    case "remove":
                        RemoveCommand(dict);
                        break;
                    default:
                        break;
                }
            }
        }