Example #1
0
        private static void CreatePersonAddedDatabase()
        {
            /* TODO: create person objects and put them in the PhoneBook and database
             * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
             * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
             */
            var person = new Person
            {
                Name        = "John Smith",
                PhoneNumber = "(248) 123-4567",
                Address     = "1234 Sand Hill Dr, Royal Oak, MI"
            };

            _phonebook.AddPerson(person);

            person.Name        = "Cynthia Smith";
            person.PhoneNumber = "(824) 128-8758";
            person.Address     = "875 Main St, Ann Arbor, MI";
            _phonebook.AddPerson(person);

            // TODO: print the phone book out to System.out
            var all = _phonebook.GetAll();

            Console.WriteLine("======TODO: print the phone book out to System.out======");
            foreach (var p in all)
            {
                PrintPerson(p);
            }
        }
Example #2
0
        private static void Main(string[] args)
        {
            try{
                Console.WriteLine("Creating new DB. Wait...");
                var book = new PhoneBook();
                book.Initialize();
                Console.WriteLine("Done initializing. Adding 2 default persons.");
                var p = new Person {
                    Name        = "John Smith",
                    PhoneNumber = "(248) 123-4567",
                    Address     = "1234 Sand Hill Dr, Royal Oak, MI"
                };
                var c = new Person {
                    Name        = "Cynthia Smith",
                    PhoneNumber = "(824) 128-8758",
                    Address     = "875 Main St, Ann Arbor, MI"
                };
                book.AddPerson(p);
                book.AddPerson(c);

                Person[] pers = book.FindAll();

                foreach (Person s in pers)
                {
                    Console.WriteLine(s.Name + ", " + s.Address + ", " + s.PhoneNumber);
                }
                Console.WriteLine("Total count: " + pers.Length);
                Console.WriteLine("Searching for a given person.");

                Person n = book.FindPerson("Cynthia Smith");
                Console.WriteLine("Found: " + n.Name + " " + n.Address + " " + n.PhoneNumber);
                Console.WriteLine("Adding new person: ");
                Console.WriteLine("Enter the name, phone, address, separated by comma : ");

                string entry = Console.ReadLine();
                if (entry != null)
                {
                    string[] entries = entry.Split(',');

                    book.AddPerson(new Person {
                        Name = entries[0], PhoneNumber = entries[1], Address = entries[2]
                    });
                }

                Console.WriteLine("New entry added!");
                Console.WriteLine();
                pers = book.FindAll();

                foreach (Person s in pers)
                {
                    Console.WriteLine(s.Name + ", " + s.Address + ", " + s.PhoneNumber);
                }
                Console.WriteLine("New count: " + pers.Length);
                Console.ReadLine();
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            PhoneBook phonebook = new PhoneBook();

            try
            {
                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */

                //  The database does not exist so create it
                DatabaseUtil.initializeDatabase();

                //  Create person objects
                Person johnSmith = new Person()
                {
                    name        = "John Smith",
                    address     = "1234 Sand Hill Dr, Royaml Oak, MI",
                    phoneNumber = "(248) 123-4567"
                };

                Person cynthiaSmith = new Person()
                {
                    name        = "Cynthia Smith",
                    address     = "875 Main St, Ann Arbor, MI",
                    phoneNumber = "(824) 128-8758"
                };


                // Insert the new person objects into the database
                phonebook.AddPerson(johnSmith);
                phonebook.AddPerson(cynthiaSmith);

                // Print the phone book out to System.out
                foreach (var person in phonebook.GetPeople())
                {
                    //  Write out list of people to console
                    Console.WriteLine("Name: {0}, Number: {1}, Address: {2}\n", person.name, person.phoneNumber, person.address);
                }


                // Find Cynthia Smith and print out just her entry
                Person cynthia = phonebook.FindPerson("Cynthia", "Smith");
                //  Print out Cynthias' details to console
                Console.WriteLine("Name: {0}, Number: {1}, Address: {2}\n", cynthia.name, cynthia.phoneNumber, cynthia.address);
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #4
0
        /// <summary>
        /// Adds New person details in the database
        /// </summary>
        public void AddNewPerson()
        {
            Person p = new Person();

            Console.WriteLine("Enter the person name");
            p.name = Console.ReadLine();
            Console.WriteLine("Enter the person phoneNumber");
            p.phoneNumber = Console.ReadLine();
            Console.WriteLine("Enter the person address");
            p.address = Console.ReadLine();
            phonebook.AddPerson(p);
            GetAllPersons();
        }
Example #5
0
        static void Main(string[] args)
        {
            try
            {
                Person[] persons =
                {
                    new Person("John Smith",    "(248) 123-4567", "1234 Sand Hill Dr, Royal Oak, MI"),
                    new Person("Cynthia Smith", "(824) 128-8758", "875 Main St, Ann Arbor, MI")
                };

                DatabaseUtil.InitializeDatabase(null);

                PhoneBook phoneBook = new PhoneBook();
                phoneBook.AddPerson(persons[0]);
                phoneBook.AddPerson(persons[1]);

                for (int i = 0; i < phoneBook.Length; ++i)
                {
                    Console.WriteLine(phoneBook[i].GetInfo);
                }

                Person p = phoneBook.FindPerson("Cynthia Smith");
                Console.WriteLine(p?.GetInfo);

                Console.ReadLine();

                #region Test



                //Console.ReadLine();
                ///* TODO: create person objects and put them in the PhoneBook and database
                //* John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                //* Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                //*/

                //// TODO: print the phone book out to System.out
                //// TODO: find Cynthia Smith and print out just her entry
                //// TODO: insert the new person objects into the database


                #endregion
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            try
            {
                var dbConnection = new SQLiteConnection("Data Source= MyDatabase.sqlite;Version=3;");
                dbConnection.Open();
                SQLiteCommand command =
                    new SQLiteCommand(
                        "drop table PHONEBOOK",
                        dbConnection);
                command.ExecuteNonQuery();
                DatabaseUtil.InitializeDatabase();

               //Add phonebooks to In-memory Phonebook Collection
                var phoneBook = new PhoneBook(new PersonRepository());
                phoneBook.AddPerson(new Person()
                {
                    Name = "John Smith",
                    Address = "1234 Sand Hill Dr, Royal Oak, MI",
                    PhoneNumber = "(248) 123-4567"
                });
                phoneBook.AddPerson(new Person()
                {
                    Name = "Cynthia Smith",
                    Address = "875 Main St, Ann Arbor, MI",
                    PhoneNumber = "(824) 128-8758"
                });

                //Print phonebook
                Console.WriteLine("---------PRINT Phonebook");
                Console.WriteLine(phoneBook.ToString());

                //get and print cynthia
                Console.WriteLine("---------PRINT Cynthia");
                var person = phoneBook.FindPerson("Cynthia Smith");
                Console.WriteLine(person.ToString());

                //persist in-memory phonebook collection to DB
                phoneBook.Persist();

                Console.WriteLine("Press Enter to exit");
                Console.ReadLine();
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #7
0
        private static void Main(string[] args)
        {
            try
            {
                DatabaseUtil.initializeDatabase();

                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */
                // TODO: print the phone book out to System.out
                Console.Write("\n\n************All Records in the PhoneBook Table!************\n");
                phonebook.GetAll();

                // TODO: insert the new person objects into the database
                Console.Write("************\n\nNew Person Added in the PhoneBook Table !\n");
                phonebook.AddPerson();


                // TODO: find Cynthia Smith and print out just her entry
                Console.Write("************\n\n Find the Person in PhoneBook Table !\n");
                phonebook.FindPerson("Cynthia", "Smith");

                Console.Write("End !");
                Console.ReadLine();
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Example #8
0
 /// <summary>
 /// Add new persons to database
 /// </summary>
 private void AddNewPersons()
 {
     /* TODO: create person objects and put them in the PhoneBook and database
      * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
      * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
      */
     phonebook.AddPerson(new Person {
         name = "Chris Johnson", phoneNumber = "(321) 231-7876", address = "452 Freeman Drive, Algonac, MI"
     });
     phonebook.AddPerson(new Person {
         name = "Dave Williams", phoneNumber = "(231) 502-1236", address = "285 Huron St, Port Austin, MI"
     });
     phonebook.AddPerson(new Person {
         name = "John Smith", phoneNumber = "(248) 123-4567", address = "1234 Sand Hill Dr, Royal Oak, MI"
     });
     phonebook.AddPerson(new Person {
         name = "Cynthia Smith", phoneNumber = "(824) 128-8758", address = "875 Main St, Ann Arbor, MI"
     });
 }
Example #9
0
        static void Main(string[] args)
        {
            /* TODO: create person objects and put them in the PhoneBook and database
             * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
             * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
             */

            phonebook.AddPerson(new Person("John Smith", "(248) 123-4567", "1234 Sand Hill Dr, Royal Oak, MI"));
            phonebook.AddPerson(new Person("Cynthia Smith", "(824) 128-8758", "875 Main St, Ann Arbor, MI"));


            // TODO: print the phone book out to System.out
            Console.WriteLine("All phonebook entries \n");
            foreach (var person in phonebook)
            {
                Console.WriteLine(person);
            }
            Console.WriteLine("\n");


            // TODO: find Cynthia Smith and print out just her entry
            Console.WriteLine("Cythia's phonebook entry \n");
            var cynthia = phonebook.FindPerson("Cynthia", "Smith");

            Console.WriteLine(cynthia);

            try
            {
                DatabaseUtil.initializeDatabase();

                // TODO: insert the new person objects into the database
                DatabaseUtil.InsertPeople(phonebook);
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }

            Console.ReadLine();
        }
Example #10
0
        public void addPerson()
        {
            //Arrange
            var pBook = new PhoneBook();
            var person = new Person()
            {
                Name = "test person"
            };

            //Act
            pBook.AddPerson(person);

            Assert.Pass();
        }
Example #11
0
        static void Main(string[] args)
        {
            var context = new PhoneBookContext();

            try
            {
                DatabaseUtil.initializeDatabase(context);

                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */
                var John    = new Person("John", "Smith", "(248) 123 - 4567", "1234 Sand Hill Dr", "Royal Oak", "MI");
                var Cynthia = new Person("Cynthia", "Smith", "(824) 128 - 8758", "875 Main St", "Ann Arbor", "MI");

                var phoneBook = new PhoneBook(context);
                phoneBook.AddPerson(John);
                phoneBook.AddPerson(Cynthia);

                // TODO: print the phone book out to System.out
                new PhoneBookPrinter().Print(phoneBook);

                // TODO: find Cynthia Smith and print out just her entry
                var cynthiaRecord = phoneBook.Find(m => m.FirstName == "Cynthia" && m.LastName == "Smith")
                                    .FirstOrDefault();
                Console.WriteLine();
                Console.WriteLine(cynthiaRecord?.ToString());

                // TODO: insert the new person objects into the database
                Console.ReadLine();
                DatabaseUtil.CleanUp(context);
            }
            finally
            {
                DatabaseUtil.CleanUp(context);
            }
        }
Example #12
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("\nHello, Welcome to Phone Book App! \n");

                DatabaseUtil.initializeDatabase();

                /* TODO: create person objects and put them in the PhoneBook and database
                 * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI
                 * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI
                 */
                Person objPerson = new Person()
                {
                    name        = "John Smith",
                    phoneNumber = "(248) 123-4567",
                    address     = "1234 Sand Hill Dr, Royal Oak, MI"
                };
                phonebook.AddPerson(objPerson);

                objPerson = new Person()
                {
                    name        = "Cynthia Smith",
                    phoneNumber = "(824) 128-8758",
                    address     = "875 Main St, Ann Arbor, MI"
                };
                phonebook.AddPerson(objPerson);


                // TODO: print the phone book out to System.out
                var phoneBookData = phonebook.GetPhoneBook();
                if (phoneBookData != null)
                {
                    Console.WriteLine("List of Contacts from Phone Book:");
                    for (var i = 0; i < phoneBookData.Rows.Count; i++)
                    {
                        var contactNum = i + 1;
                        Console.WriteLine("\n Contact " + contactNum + " : \n Name: " + phoneBookData.Rows[i][0] + "\n Phone: " + phoneBookData.Rows[i][1] + "\n Address: " + phoneBookData.Rows[i][2]);
                    }
                }

                // TODO: find Cynthia Smith and print out just her entry
                var person = phonebook.findPerson("Cynthia", "Smith");
                if (person.name != null)
                {
                    Console.WriteLine("\n Cynthia Smith is available in Phone book and below are the details.");
                    Console.WriteLine(" Name: " + person.name + "\n Phone: " + person.phoneNumber + "\n Address: " + person.address);
                }
                else
                {
                    Console.WriteLine("\n Oops!, Cynthia Smith is not available in Phone book.");
                }

                // TODO: insert the new person objects into the database
                Console.WriteLine("\nEnter 1 to add new contact Or any other key to Proceed.");
                var input = Console.ReadKey();
                if (input.KeyChar.ToString() == "1")
                {
                    AddNewContact();
                }


                Console.WriteLine("\n ***Thank you, Have a nice day.***");
                Console.Read();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Encountered as exception while running the process with below message.\n" + ex.Message);
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }