public string ConvertPhoneListToPipeSV(Contact contact) { List<Phone> phoneList = contact.Phones; if (phoneList.Count > 1) { List<string> allPhoneStrings = new List<string>(); //see if it makes a difference using array vs list here. foreach (var phone in phoneList) { string phoneString = string.Format("{0}^{1}", phone.PhoneType, phone.PhoneNumber); allPhoneStrings.Add(phoneString); } string completePhoneString = string.Join("%", allPhoneStrings) + "%"; //can someone remind me why the heck I added the trailing "%"? 5/14/14 return completePhoneString; } if (phoneList.Count == 1) { string completePhoneString = string.Format("{0}^{1}", phoneList.First().PhoneType, phoneList.First().PhoneNumber); return completePhoneString; } string phoneMessage = "There are no phone numbers for this contact"; return phoneMessage; }
public void PrintSingleContact(Contact person) { Console.WriteLine("Name: {0} {1} ", person.FirstName, person.LastName); Console.WriteLine("------------------------------"); foreach (var phone in person.Phones) { Console.WriteLine("{0} Phone: {1}", phone.PhoneType, phone.PhoneNumber); } Console.WriteLine("----------------------------------"); foreach (var address in person.Addresses) { Console.WriteLine("{0} Address: {1}, {2}, {3}, {4}", address.AddressType, address.Street, address.City, address.State, address.Zip); } Console.WriteLine("---------------------------------------"); foreach (var email in person.Emails) { Console.WriteLine("{0} email: {1}", email.EmailType, email.EmailAddress); } Console.WriteLine("---------------------------------------"); Console.WriteLine("You entered these notes about {0} {1}: \n{2}", person.FirstName, person.LastName, person.NotesField); Console.ReadLine(); }
public List<Contact> ContactListFromArry(string[] allLines) { List<Contact> contacts = new List<Contact>(); foreach (string line in allLines) { string[] columns = line.Split('|'); Contact contact = new Contact(); contact.FirstName = columns[0]; contact.LastName = columns[1]; string phoneList = columns[2]; //can i make the next 15 lines into a load phone list method that takes in a string phoneList and returns a List<Phone>? // var allPhones = new List<Phone>(); //does this make an empty list or is it filled with return result of LoadPhoneList? List<Phone> allPhones = LoadPhoneList(phoneList); contact.Phones = allPhones; string addressList = columns[3]; List<Address> allAddresses = LoadAddressList(addressList); contact.Addresses = allAddresses; string emailList = columns[4]; List<Email> allEmails = LoadEmailList(emailList); contact.Emails = allEmails; contact.NotesField = columns[5]; contact.VolumeName = columns[6]; contact.TimesSelected = int.Parse(columns[7]); contacts.Add(contact); } return contacts; }
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; }
private void PopulatePhonesList(Contact newContact) { bool isNoMorePhones = false; do { Phone newPhone = new Phone(); string userInput; Console.Write("Enter Phone description (i.e. work, home, cell etc) or 'X' to move on: "); userInput = Console.ReadLine(); if (userInput.ToUpper() == "X") { isNoMorePhones = true; Console.Clear(); } else { newPhone.PhoneType = userInput; Console.Clear(); Console.Write("Enter {1}'s {0} Phone number: ", newPhone.PhoneType, newContact.FirstName); newPhone.PhoneNumber = Console.ReadLine(); newContact.Phones.Add(newPhone); } } while (!isNoMorePhones); }
private void PopulateEmailList(Contact newContact) { bool isNoMoreEmails = false; do { //make do while loop to continue adding phones to phones list Email newEmail = new Email(); string userInput; Console.Write("What sort of email account is this? \n(work, personal, etc... or hit 'X' to move on): "); userInput = Console.ReadLine(); Console.Clear(); if (userInput.ToUpper() == "X") { isNoMoreEmails = true; Console.Clear(); } else { newEmail.EmailType = userInput; Console.Write("Enter {1}'s {0} email: ", newEmail.EmailType, newContact.FirstName); newEmail.EmailAddress = Console.ReadLine(); newContact.Emails.Add(newEmail); } } while (!isNoMoreEmails); }
private void PopulateAddressList(Contact newContact) { bool isNoMoreAddresses = false; do { Address newAddress = new Address(); string userInput; Console.WriteLine("Enter Address description (i.e. work, home, vacation etc) or 'X' to move on: "); userInput = Console.ReadLine(); Console.Clear(); if (userInput.ToUpper() == "X") { isNoMoreAddresses = true; Console.Clear(); } else { newAddress.AddressType = userInput; Console.WriteLine("Enter {1}'s {0} address Street number: ", newAddress.AddressType, newContact.FirstName); newAddress.Street = Console.ReadLine(); Console.WriteLine(); Console.Write("What city is {0}'s {1} in?: ", newContact.FirstName, newAddress.AddressType); newAddress.City = Console.ReadLine(); Console.WriteLine(); Console.Write("What State is {0}'s {1} address in?: ", newContact.FirstName, newAddress.AddressType); newAddress.State = Console.ReadLine(); Console.WriteLine(); Console.Write("What zipcode is {0}'s {1} in: ", newContact.FirstName, newAddress.AddressType); newAddress.Zip = Console.ReadLine(); Console.Clear(); newContact.Addresses.Add(newAddress); } } while (!isNoMoreAddresses); }
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); }
private string ConvertEmailListToPipeSV(Contact contact) { List<Email> emailList = contact.Emails; if (emailList.Count>1) { List<string> allEmailStrings = new List<string>(); foreach (var email in emailList) { string emailString = string.Format("{0}^{1}", email.EmailType, email.EmailAddress); allEmailStrings.Add(emailString); //forgoing for-loop } string completeEmailString = string.Join("%", allEmailStrings) + "%"; return completeEmailString; } if (emailList.Count == 1) { string completeEmailString = string.Format("{0}^{1}", emailList.First().EmailType, emailList.First().EmailAddress); return completeEmailString; } string emailMessage = "There are no emails stored for this contact"; return emailMessage; }
//for writing/saving to file private string ConvertContactToPipeSV(Contact contact) { string phonesToFile = ConvertPhoneListToPipeSV(contact); string addressesToFile = ConvertAddressListToPipeSV(contact); string emailToFile = ConvertEmailListToPipeSV(contact); return string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}", contact.FirstName, contact.LastName, phonesToFile, addressesToFile, emailToFile, contact.NotesField, contact.VolumeName, contact.TimesSelected); }
private string ConvertAddressListToPipeSV(Contact contact) { List<Address> addressList = contact.Addresses; if (addressList.Count > 1) { List<string> allAddressStrings = new List<string>(); foreach (var address in addressList) { string addressString = string.Format("{0}^{1}^{2}^{3}^{4}", address.AddressType, address.Street, address.City, address.State, address.Zip); allAddressStrings.Add(addressString); } string completeAddressString = string.Join("%", allAddressStrings) + "%"; return completeAddressString; } if (addressList.Count ==1) { string completeAddressString = string.Format("{0}^{1}^{2}^{3}^{4}", addressList.First().AddressType, addressList.First().Street, addressList.First().City, addressList.First().State, addressList.First().Zip); return completeAddressString; } string addressMessage = "There are no addresses stored for this contact"; return addressMessage; }