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; }
public List<FileName> LoadListOfExistingFiles() { if (File.Exists(FileTrackerFileName)) { string[] allLines = File.ReadAllLines(FileTrackerFileName); List<FileName> currentVolumes = new List<FileName>(); foreach (var line in allLines) { FileName volume = new FileName(); volume.NameOfFile = line; currentVolumes.Add(volume); } return currentVolumes; } return new List<FileName>(); }