internal static void UpdateContact(int id) { if (id == 0) { return; } else if (ContactList.ContainsKey(id)) { do { Console.Clear(); ContactModel c = GetContactFromList(id); ConsoleLogging.PrintContactInfo(id, c); Console.WriteLine("What do you want to update?"); string propertyToUpdate = Console.ReadLine(); UpdateProperty(c, propertyToUpdate); } while (ConsoleLogging.UpdateAgain()); } else { ConsoleLogging.ContactDoesNotExist(); } }
public static void ReadAllContacts() {// This Method Reads all the Contacts in the List and calls the ConsoleLogging.DisplayContact Method to display them Console.WriteLine(); Console.WriteLine("Contact List:"); foreach (var contact in PhoneBook.ContactList) { ConsoleLogging.DisplayContact(contact); } }
internal static void CreateContact(int key) { ContactModel contact = new ContactModel(); ConsoleLogging.GetUserInformation(contact); while (!ContactList.TryAdd(++key, contact)) { } }
private static ContactModel GetContactFromList(int id) { ContactModel c; while (!ContactList.TryGetValue(id, out c)) { ConsoleLogging.ContactDoesNotExist(); id = ConsoleLogging.GetContactToUpdate(); } return(c); }
private static void Execute() { int contactId; do { Console.Clear(); ConsoleLogging.WhichActionText(); var userChoice = Console.ReadKey(); Console.WriteLine(); switch (userChoice.Key) { case ConsoleKey.D1: case ConsoleKey.NumPad1: Console.Clear(); PhoneBook.CreateContact(PhoneBook.ContactList.Count); ConsoleLogging.PressEnter(); break; case ConsoleKey.D2: case ConsoleKey.NumPad2: Console.Clear(); PhoneBook.GetAllContacts(); ConsoleLogging.PressEnter(); break; case ConsoleKey.D3: case ConsoleKey.NumPad3: Console.Clear(); contactId = ConsoleLogging.GetContactToUpdate(); PhoneBook.UpdateContact(contactId); ConsoleLogging.PressEnter(); break; case ConsoleKey.D4: case ConsoleKey.NumPad4: Console.Clear(); contactId = ConsoleLogging.GetContactToDelete(); PhoneBook.DeleteContact(contactId); ConsoleLogging.PressEnter(); break; case ConsoleKey.D5: case ConsoleKey.NumPad5: Console.Clear(); FileMaster.WriteFile(PhoneBook.ContactList); Console.WriteLine("Thank You!"); Environment.Exit(0); break; } } while (true); }
static void Main(string[] args) { ConsoleLogging.IntroText(); PhoneBook.ContactList = FileMaster.ReadFile(); if (PhoneBook.ContactList.Count == 0) { ConsoleLogging.FirstTimeText(); PhoneBook.CreateContact(0); } Execute(); }
internal static void DeleteContact(int id) { if (id == 0) { return; } else if (ContactList.Remove(id)) { Console.WriteLine("Contact removed!"); } else { ConsoleLogging.DeleteContactErrorText(); } }
internal static void GetAllContacts() { if (ContactList.Count == 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("No contacts!!!"); Console.WriteLine(); Console.ResetColor(); return; } var ordered = ContactList.OrderBy(x => x.Value.FirstName).ThenBy(x => x.Value.LastName); foreach (var contact in ordered) { ConsoleLogging.PrintContactInfo(contact.Key, contact.Value); } }
private static void UpdateProperty(ContactModel c, string propertyToUpdate) { switch (propertyToUpdate.ToLower()) { case "first name": c.FirstName = ConsoleLogging.GetContactInfo("new first name"); break; case "last name": c.LastName = ConsoleLogging.GetContactInfo("new last name"); break; case "phone number": c.PhoneNumber = ConsoleLogging.GetContactInfo("new phone number"); break; case "address": c.Address = ConsoleLogging.GetContactInfo("new address"); break; case "email address": case "email": c.EmailAddress = ConsoleLogging.GetContactInfo("new email address"); break; case "dob": case "birthday": c.DOB = ConsoleLogging.GetContactInfo(); break; default: ConsoleLogging.InvalidInputText(); Console.Write("Please press enter . . . "); Console.ReadLine(); break; } }
static void Main(string[] args) { Console.WriteLine("Welcome to your Phone Book App"); //Ask the user to select an option string userSelection; bool stopAppliction = false; bool phoneBookCreated = false; while (stopAppliction == false) { ConsoleLogging.DisplayMenu(); Console.WriteLine(); Console.Write("Please enter your selection: "); userSelection = Console.ReadLine(); switch (userSelection) { case "1": Contact c = User.CreateContact(); PhoneBook.ContactList.Add(c); phoneBookCreated = true; break; case "2": if (phoneBookCreated) { User.ReadAllContacts(); } else { Console.WriteLine("Sorry You Need to Add a Contact First"); } break; case "3": if (phoneBookCreated) { //NOTE - This Requires the User to enter the entire Contact Information //Add Logic to allow the user to select and update only the fields they want to change PhoneBook.ContactList.Remove(User.MatchContact()); Console.WriteLine("The Contact Has been Removed, Enter the Updated Contact Information"); Contact updatedContact = User.CreateContact(); PhoneBook.ContactList.Add(updatedContact); phoneBookCreated = true; } else { Console.WriteLine("Sorry You Need to Add a Contact First"); } break; case "4": if (phoneBookCreated) { PhoneBook.ContactList.Remove(User.MatchContact()); Console.WriteLine("The Contact Has been Removed from your List."); } else { Console.WriteLine("Sorry You Need to Add a Contact First"); } break; case "5": stopAppliction = true; break; } } Console.WriteLine("Thanks for using the Phone Book App"); }