// add person details into phonebook
 public void addPerson(Person newPerson)
 {
     using (SQLiteConnection dbconnection = DatabaseUtil.GetConnection())
     {
         // realtime we can create a storeprocedure instead of the T-SQL
         SQLiteCommand command = new SQLiteCommand(string.Format("INSERT INTO PHONEBOOK (NAME, PHONENUMBER, ADDRESS) VALUES('{0}','{1}', '{2}')",newPerson.name,newPerson.phoneNumber,newPerson.address), dbconnection);
         int result = command.ExecuteNonQuery();
     }
 }
Exemple #2
0
 public void SavePerson(Person person)
 {
     var dbConnection = DatabaseUtil.GetConnection();
     var command = new SQLiteCommand(
                 "INSERT INTO PHONEBOOK (NAME, PHONENUMBER, ADDRESS) VALUES(?,?,?)",
                 dbConnection);
     command.Parameters.AddWithValue("Name",person.Name);
     command.Parameters.AddWithValue("PhoneNumber",person.PhoneNumber);
     command.Parameters.AddWithValue("Address",person.Address);
     command.ExecuteNonQuery();
 }
Exemple #3
0
        public void addPerson()
        {
            //Arrange
            var pBook = new PhoneBook();
            var person = new Person()
            {
                Name = "test person"
            };

            //Act
            pBook.AddPerson(person);

            Assert.Pass();
        }
        static void Main(string[] args)
        {
            try
            {
                //DatabaseUtil.CleanUp();
                DatabaseUtil.initializeDatabase();
                PhoneBook phonebook = new PhoneBook();
                /* 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: insert the new person objects into the database
                Person objPerson1 = new Person { name = "John Smith", phoneNumber = "(248) 123-4567", address = "1234 Sand Hill Dr, Royal Oak, MI" };
                Person objPerson2 = new Person { name = "Cynthia Smith", phoneNumber = "(824) 128-8758", address = "875 Main St, Ann Arbor, MI" };
                phonebook.addPerson(objPerson1);
                phonebook.addPerson(objPerson2);

                // TODO: print the phone book out to System.out
                Console.WriteLine("###########PHONE BOOK##############");
                foreach (Person person in phonebook.GetPhoneBook)
                {
                    Console.WriteLine("Name: {0}, Phone Number: {1}, Address: {2}", person.name, person.phoneNumber, person.address);
                }
                Console.WriteLine("###################################");
                // TODO: find Cynthia Smith and print out just her entry
                string strFN = "Cynthia";
                string strLN = "Smith";
                Person findpersion = phonebook.findPerson(strFN, strLN);
                Console.WriteLine("Name: " + findpersion.name);
                Console.WriteLine("Phone Number: " + findpersion.phoneNumber);
                Console.WriteLine("Address: "+ findpersion.address);

                Console.ReadLine();
            }
            finally
            {
                DatabaseUtil.CleanUp();
            }
        }
Exemple #5
0
 public void AddPerson(Person person)
 {
     _persons.Add(person);
 }
Exemple #6
0
 static void PrintPerson(Person person)
 {
     Console.WriteLine("Name : {0}, Address : {1}, PhoneNumber : {2}",
                                         person.Name, person.Address, person.PhoneNumber);
 }