Ejemplo n.º 1
0
        public List<Contact> Execute()
        {
            var fm = new FileManager();
            List<FileName> volumeNames = fm.LoadListOfExistingFiles();

            string volumeName = DisplayVolumes(volumeNames);
            WriteHeader(volumeName);
            string fileName = volumeName;//added this line because seemed to lose filename in WriteHeader method.
              List<Contact> contactList =  fm.LoadContactsFromFile(fileName);//for some reason this is returning an empty list. Why?!
            return contactList;
        }
Ejemplo n.º 2
0
        public Contact FillNewContactObject()
        {
            Contact newContact = new Contact();

               // AllFiles existingFiles = new AllFiles();
            FileName fileName = new FileName();

            FileManager fm = new FileManager();

            List<FileName> volumeNames = fm.LoadListOfExistingFiles();

            Console.WriteLine("Add your contact to an existing addressbook by entering one of the following: ");

            if (volumeNames.Any())
            {
                foreach (var volumeName in volumeNames)
                {
                    Console.WriteLine(volumeName.NameOfFile);
                }
                Console.WriteLine("Or, create a new address book by entering a new title: ");

            }
            else
            {
                Console.WriteLine("\nActually, you have no existing address books! \nCreate your first now:");
            }

            string userInput = Console.ReadLine();
            newContact.VolumeName = userInput;
            fileName.NameOfFile = userInput;
            int count = 0;

            foreach (var volumeName in volumeNames)
            {
                if (volumeName.NameOfFile==fileName.NameOfFile)
                {
                    count++;
                }

            }
            if (count == 0)
            {
                volumeNames.Add(fileName);
            }

            //if (!volumeNames.Contains(fileName)) grrrr. why doesn't this work? adds everytime.
            //{
            //    //could add validation"are you sure you want to add the new addressbook "blah"?
            //    volumeNames.Add(fileName);
            //}

            fm.SaveVolumeNamesToFileTracker(volumeNames);
            Console.Clear();

            Console.Write("Enter first name: ");
            newContact.FirstName = Console.ReadLine();

            Console.WriteLine();

            Console.Write("Enter last name: ");
            newContact.LastName = Console.ReadLine();

            Console.Clear();

            Console.Write("Enter any notes you would like to associate with {0} {1}\nNotes Field: ", newContact.FirstName, newContact.LastName);
            newContact.NotesField = Console.ReadLine();

            Console.Clear();

            PopulatePhonesList(newContact);

            PopulateAddressList(newContact);

            PopulateEmailList(newContact);

            newContact.TimesSelected = 0;
            return newContact;
        }
Ejemplo n.º 3
0
 public void UpdateAddressBookFile(Contact contact)
 {
     FileManager fm = new FileManager();
     //  string fileName="";
     string fileName = contact.VolumeName;
     List<Contact> allContacts = fm.LoadContactsFromFile(fileName);
     allContacts.Add(contact);
     fm.SaveContactsToFile(allContacts);
 }