Exemplo n.º 1
0
        public static void FillAddressBook(AddressBook addressBook)
        {
            int choice;

            do
            {
                Console.WriteLine("\nMenu : \n1.Add Contact \n2.Edit Contact \n3.Delete Contact\n0.Exit");
                choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Contact contact = new Contact();
                    SetContactDetails(contact);
                    addressBook.AddContact(contact);
                    break;

                case 2:
                    Console.WriteLine("Enter the Phone Number of Contact you wish to Edit");
                    long phoneNumber = long.Parse(Console.ReadLine());
                    int  index       = addressBook.FindByPhoneNum(phoneNumber);
                    if (index == -1)
                    {
                        Console.WriteLine("No Contact Exists With Following Phone Number");
                        continue;
                    }
                    else
                    {
                        Contact contact2 = new Contact();
                        SetContactDetails(contact2);
                        addressBook.ContactList[index] = contact2;
                        Console.WriteLine("Contact Updated Successfully");
                    }
                    break;

                case 3:
                    Console.WriteLine("Enter the First Name of Contact you wish to delete");
                    string fname = Console.ReadLine();
                    int    idx   = addressBook.FindByFirstName(fname);
                    if (idx == -1)
                    {
                        Console.WriteLine("No Contact Exists with Following First Name");
                        continue;
                    }
                    else
                    {
                        addressBook.DeleteContact(idx);
                        Console.WriteLine("Contact Deleted Successfully");
                    }
                    break;
                }
            } while (choice != 0);
        }