예제 #1
0
        public static void CheckCurentContacts()
        {
            DAOContact     dao      = new DAOContact();
            List <Contact> contacts = dao.FindAll();

            foreach (Contact c in contacts)
            {
                c.Print();
            }
        }
예제 #2
0
        public static List <Contact> Search(Dictionary <int, string> search, long user_id)
        {
            DAOContact dao = new DAOContact(user_id);

            search.TryGetValue(INDEX_FIRSTNAME, out string firstname);
            search.TryGetValue(INDEX_LASTNAME, out string lastname);
            search.TryGetValue(INDEX_EMAIL, out string email);
            search.TryGetValue(INDEX_PHONE, out string phone);

            return(dao.FindByMultiCriteria(firstname, lastname, email, phone));
        }
예제 #3
0
        public static void CheckUsers()
        {
            DAOUser     daoUser = new DAOUser();
            List <User> users   = daoUser.FindAll();

            DAOContact daoContact = new DAOContact();

            foreach (User c in users)
            {
                c.Print();
                daoContact.FindOneById(c.Contact_Id).Print();
            }
        }
예제 #4
0
        public static void AddContact(Dictionary <string, string> c, long current_user)
        {
            DAOContact dao = new DAOContact();

            c.TryGetValue("firstname", out string firstname);
            c.TryGetValue("lastname", out string lastname);
            c.TryGetValue("email", out string email);
            c.TryGetValue("phone", out string phone);

            phone = phone == "" ? null : phone;
            email = email == "" ? null : email;

            Contact contact = new Contact(firstname, lastname, email, phone);

            dao.Create(contact, current_user);
        }
예제 #5
0
        public static void UpdateContact(Dictionary <string, string> c)
        {
            DAOContact dao = new DAOContact();

            c.TryGetValue("id", out string id);
            c.TryGetValue("firstname", out string firstname);
            c.TryGetValue("lastname", out string lastname);
            c.TryGetValue("email", out string email);
            c.TryGetValue("phone", out string phone);

            phone = phone == "" ? null : phone;
            email = email == "" ? null : email;

            Contact contact = new Contact(long.Parse(id), firstname, lastname, email, phone);

            dao.Update(contact);
        }
예제 #6
0
        public static void TestContactQuerys()
        {
            DAOContact dao = new DAOContact();


            List <Contact> contacts   = new List <Contact>();
            List <Contact> dbContacts = new List <Contact>();

            contacts.Add(new Contact("Benoit", "Sauvage", "*****@*****.**", "+1 (514) 111-2222"));
            contacts.Add(new Contact("Bob", "Durand", null, "+1 (514) 111-3333"));
            contacts.Add(new Contact("James", "Bob", "*****@*****.**", "+1 (254) 220-2659"));
            contacts.Add(new Contact("Pierre", "Martin", "*****@*****.**"));

            // PRINT
            Console.WriteLine("=== BEFORE CREATE ===");
            Console.WriteLine();
            foreach (Contact contact in contacts)
            {
                contact.Print();
            }

            // CREATE
            foreach (Contact contact in contacts)
            {
                dao.Create(contact, 1);
            }

            // FIND ALL
            foreach (Contact contact in dao.FindAll())
            {
                dbContacts.Add(contact);
            }


            // PRINT
            Console.WriteLine("=== DB BEFORE UPDATE ===");
            Console.WriteLine();
            foreach (Contact contact in dbContacts)
            {
                contact.Print();
            }

            // UPDATE
            Contact contact1 = dbContacts[0];

            contact1.Firstname = "Bob";
            contact1.Email     = "*****@*****.**";

            dao.Update(contact1);

            // FIND ONE BY ID
            Contact contact3 = dao.FindOneById(dbContacts[2].Id);

            // UPDATE
            contact3.Phone = "+1 (514) 111-4444";
            dbContacts[2]  = contact3;

            dao.Update(contact3);

            // FIN ALL
            dbContacts = dao.FindAll();

            // PRINT
            Console.WriteLine("=== DB AFTER UPDATE ===");
            Console.WriteLine();
            foreach (Contact contact in dbContacts)
            {
                contact.Print();
            }


            //SEARCH BY NAME
            Console.WriteLine("=== TEST SEARCH BY NAME (\"Bob\") ===");
            Console.WriteLine();
            List <Contact> contact4 = dao.FindByName("Bob");

            foreach (Contact contact in contact4)
            {
                contact.Print();
            }

            //SEARCH BY EMAIL
            Console.WriteLine("=== TEST SEARCH BY EMAIL (\"Jam\") ===");
            Console.WriteLine();
            List <Contact> contact5 = dao.FindByEmail("Jam");

            foreach (Contact contact in contact5)
            {
                contact.Print();
            }

            //SEARCH BY PHONE
            Console.WriteLine("=== TEST SEARCH BY PHONE (\"22\") ===");
            Console.WriteLine();
            List <Contact> contact6 = dao.FindByPhone("22");

            foreach (Contact contact in contact6)
            {
                contact.Print();
            }

            //REMOVE ALL (Juste pour pas avoir une DB de 8 bornes qui se repette a chaque fois que l'on lance un test)
            foreach (Contact contact in dao.FindAll())
            {
                dao.Remove(contact);
            }

            Console.Read();
        }