static void Main(string[] args) { _phoneBookService = new PhoneBookService(); #region Data For Testing //PhoneBook fakePhoneBook = MakeFakePhoneBook(); //Console.WriteLine(JsonConvert.SerializeObject(fakePhoneBook)); #endregion Console.WriteLine("Choose a phonebook by year"); foreach (PhoneBook phoneBook in _phoneBookService.GetPhoneBooks()) { Console.WriteLine($"* {phoneBook.Year}"); } Console.WriteLine("\nEnter a year from above:"); int userYear = int.Parse(Console.ReadLine()); PhoneBook userPhoneBook = _phoneBookService.GetPhoneBookByYear(userYear); #region Print All Contacts Console.WriteLine($"\nAll contacts from phonebook of {userPhoneBook.Year}:"); List <Contact> allContacts = _phoneBookService.GetContacts(userPhoneBook.Id.ToString()); foreach (Contact contact in allContacts) { Console.WriteLine($"{contact.FirstName} {contact.LastName} {contact.PhoneNumber} {contact.MobileNumber}"); } #endregion #region Print Contacts by FirstName letter Console.WriteLine("\nEnter a first letter of First Names:"); char userInputFirstLetter = Console.ReadLine().First(); List <Contact> contactsByFirstNameLetter = _phoneBookService.GetContactsByFirstNameFirstLetter(userPhoneBook.Id.ToString(), userInputFirstLetter); Console.WriteLine($"\nAll contacts starting with letter: {userInputFirstLetter}"); foreach (Contact contact in contactsByFirstNameLetter) { Console.WriteLine($"{contact.FirstName} {contact.LastName} {contact.PhoneNumber} {contact.MobileNumber}"); } #endregion #region Search Contacts Console.WriteLine("\nSearch contacts by last name.\nEnter a last name:"); string userInputLastName = Console.ReadLine(); List <Contact> contactsBySearch = _phoneBookService.SearchContacts(userPhoneBook.Id.ToString(), lastName: userInputLastName); foreach (Contact contact in contactsBySearch) { Console.WriteLine($"{contact.FirstName} {contact.LastName} {contact.PhoneNumber} {contact.MobileNumber}"); } #endregion Console.ReadKey(); }
static void Main(string[] args) { IPhoneBook service = new PhoneBookService(); var contacsList = new List <Contact> { new Contact { Name = "Baki", LastName = "Gervalla", Phones = new List <Phone> { new Phone { Type = "Work", Number = "044287715" }, new Phone { Type = "Home", Number = "049494949" } } }, new Contact { Name = "Denart", LastName = "Prishtina", Phones = new List <Phone> { new Phone { Type = "Home", Number = "044123123" } } }, new Contact { Name = "Urani", LastName = "England", Phones = new List <Phone> { new Phone { Type = "Cellphone", Number = "044287715" } } } }; service.Add(contacsList) .Save(); ShowContacts( service.GetContacts().OrderByFirstName() ); Console.WriteLine("Type F or L to order the list. Type D to delete a contact."); ConsoleKeyInfo key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.F: Console.Clear(); ShowContacts(service.GetContacts().OrderByFirstName()); break; case ConsoleKey.L: Console.Clear(); ShowContacts(service.GetContacts().OrderByLastName()); break; case ConsoleKey.D: Console.WriteLine("Type contact name you want to delete"); var name = Console.ReadLine(); var contact = contacsList.FirstOrDefault(x => x.Name.Equals(name)); if (contact == null) { return; } service.Delete(contact); Console.Clear(); ShowContacts(service.GetContacts().OrderByFirstName()); break; } Console.ReadLine(); }