//Write in CSV file
        public static void WriteAddressBookCSV()
        {
            string path = @"F:\MyPrograms\Assignments\A4-AddressBook\AddressBookSystem\AddressBookSystem\Utility\AddressBook.csv";

            using (var writer = new StreamWriter(path, false))
                using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
                {
                    SortContacts.SortOnConditionChooses(Contacts.listContacts);
                    csv.WriteRecords(Contacts.listContacts);
                }
        }
        //Write in JSON File
        public static void WriteAddressBookJSON()
        {
            string         path           = @"F:\MyPrograms\Assignments\A4-AddressBook\AddressBookSystem\AddressBookSystem\Utility\AddressBook.json";
            JsonSerializer jsonSerializer = new JsonSerializer();

            using (StreamWriter streamWriter = new StreamWriter(path))
                using (JsonWriter writer = new JsonTextWriter(streamWriter))
                {
                    SortContacts.SortOnConditionChooses(Contacts.listContacts);
                    jsonSerializer.Serialize(writer, Contacts.listContacts);
                    CustomPrint.PrintInRed("Saved Data Successfully");
                }
        }
Exemplo n.º 3
0
 /// <summary>View all contacts in DB.</summary>
 public static void AllContacts()
 {
     //For Sorting Accoring to sorting type choosed
     SortContacts.SortOnConditionChooses(Contacts.listContacts);
     CustomPrint.PrintInRed($"All Contacts in every address book");
     CustomPrint.PrintDashLine();
     Console.WriteLine(CustomPrint.PrintRow("AddressBookName", "Name", "Address", "City", "State", "Zip", "PhoneNo", "Email", "Date Added"));
     CustomPrint.PrintDashLine();
     foreach (AddressBookModel item in listContacts)
     {
         Console.WriteLine(item);
     }
     CustomPrint.PrintDashLine();
 }
        //Write into txt file
        public static void WriteAddressBook()
        {
            string path = @"F:\MyPrograms\Assignments\A4-AddressBook\AddressBookSystem\AddressBookSystem\Utility\AddressBook.txt";

            using (StreamWriter sr = File.AppendText(path))
            {
                SortContacts.SortOnConditionChooses(Contacts.listContacts);
                foreach (AddressBookModel personDetails in Contacts.listContacts)
                {
                    sr.WriteLine(personDetails);
                }
                sr.Close();
                CustomPrint.PrintInRed("Address Book Txt file has been Appended", false);
            }
        }
Exemplo n.º 5
0
        /// <summary>Views All contacts in same state or city for all address book.</summary>
        public static void SearchPersonByCityOrState()
        {
            //For Sorting Accoring to sorting type choosed
            SortContacts.SortOnConditionChooses(Contacts.listContacts);
            //For counting no of people in same city/state
            int slNo = 0;

            Console.Write("Enter City : ");
            string city = Console.ReadLine();

            Console.Write("Enter State : ");
            string state = Console.ReadLine();

            CustomPrint.PrintInRed("Search by City " + city + " are :\n");
            CustomPrint.PrintDashLine();
            Console.WriteLine(CustomPrint.PrintRow("AddressBookName", "Name", "Address", "City", "State", "Zip", "PhoneNo", "Email", "Date Added"));
            CustomPrint.PrintDashLine();
            foreach (AddressBookModel personDetails in listContacts.Where(x => (x.City.ToLower().Equals(city.ToLower()) && x.State.ToLower().Equals(state.ToLower()))))
            {
                Console.WriteLine(personDetails);
                slNo++;
            }
            CustomPrint.PrintDashLine();
            Console.WriteLine("\nCount by City is : " + slNo);
            CustomPrint.PrintInRed("Search by State " + state + " are :\n");
            CustomPrint.PrintDashLine();
            Console.WriteLine(CustomPrint.PrintRow("AddressBookName", "Name", "Address", "City", "State", "Zip", "PhoneNo", "Email", "Date Added"));
            CustomPrint.PrintDashLine();
            slNo = 0;
            foreach (AddressBookModel personDetails in listContacts)
            {
                if (personDetails.State.Equals(state))
                {
                    Console.WriteLine(personDetails);
                    slNo++;
                }
            }
            CustomPrint.PrintDashLine();
            Console.WriteLine("\nCount by State is : " + slNo);
        }