コード例 #1
0
        /// <summary>Deletes the contact.</summary>
        /// <param name="addressBookName">Name of the address book.</param>
        public static void DeleteContact(string addressBookName)
        {
            //gets First Name And Second Name from User using
            string[]         name           = AskDetailForDeletingOrEditing(addressBookName, "Delete");
            string           fName          = name[0];
            string           sName          = name[1];
            bool             personFound    = false;
            AddressBookModel personToDelete = new AddressBookModel();
            //loops through contacts where First Name,Second Name and AddressBookName get matched
            Func <AddressBookModel, bool> condition = item => ((item.FirstName).ToLower() == fName.ToLower() && (item.LastName).ToLower() == sName.ToLower() && item.AddressBookName == addressBookName);

            foreach (AddressBookModel item in listContacts.Where(condition))
            {
                personToDelete = item;
                personFound    = true;
                break;
            }
            //Removes the Contacts if person found
            if (personFound && AddressBookDBWork.DeleteContactFromDB(personToDelete))
            {
                listContacts.Remove(personToDelete);
                CustomPrint.PrintInRed("Person removed from Contacts in " + addressBookName, false);
            }
            //Gives error if person not found
            else
            {
                CustomPrint.PrintInMagenta("Person not found", false);
            }
        }
コード例 #2
0
        /// <summary>Adds the contacts.</summary>
        /// <param name="addressBookName">Name of the address book.</param>
        public static void AddContacts(string addressBookName)
        {
            //Creates new Contact object by getting personDeatils from AskDetailsForAdding
            AddressBookModel objContacts = new AddressBookModel(AskDetailsForAdding(addressBookName));

            //Adds objContact to listContacts if objContacts is valid
            if (AddressBookDetailsValidation.Validate(objContacts))
            {
                objContacts.DateAdded = DateTime.Now;
                if (AddressBookDBWork.AddContactToDB(objContacts))
                {
                    listContacts.Add(objContacts);
                    CustomPrint.PrintInRed($"Contact has been Added to {addressBookName}", false);
                }
                else
                {
                    CustomPrint.PrintInMagenta($"Contact has not been Added to", false);
                }
            }
            //Given Error if objContacts is invalid
            else
            {
                CustomPrint.PrintInMagenta($"Contact has not been Added to", false);
                AddContacts(addressBookName);
            }
        }
コード例 #3
0
 public static void Main()
 {
     CustomPrint.PrintInRed("*****Welcome to Address Book Program*****", false);
     //For storing saved data from file in listContacts
     AddressBookDBWork.StoreAllContactsToList();
     //Calling AddressBook Method for Choosing Option
     WorkingOnAddressBook.AddressBook();
 }
コード例 #4
0
 /// <summary>Retirves alls the contacts in given date range.</summary>
 public static void AllContactsInGivenDateRange()
 {
     try
     {
         DateTime[] dates = AskForDateRange();
         AddressBookDBWork.GetContactInGivenDateRange(dates[0], dates[1]);
     }
     catch (Exception e)
     {
         CustomPrint.PrintInMagenta(e.Message + "\nTry Again");
         AllContactsInGivenDateRange();
     }
 }
コード例 #5
0
        /// <summary>Edits the contact.</summary>
        /// <param name="addressBookName">Name of the address book.</param>
        public static void EditContact(string addressBookName)
        {
            //gets First Name And Second Name from User using
            string[] name        = AskDetailForDeletingOrEditing(addressBookName, "Edit");
            string   fName       = name[0];
            string   sName       = name[1];
            bool     personFound = false;
            //loops through contacts where First Name,Second Name and AddressBookName get matched
            Func <AddressBookModel, bool> condition = item => ((item.FirstName).ToLower() == fName.ToLower() && (item.LastName).ToLower() == sName.ToLower() && item.AddressBookName == addressBookName);

            foreach (AddressBookModel item in listContacts.Where(condition))
            {
                Console.Write("New Address : ");
                item.Address = Console.ReadLine();
                Console.Write("New City : ");
                item.City = Console.ReadLine();
                Console.Write("New State : ");
                item.State = Console.ReadLine();
                Console.Write("New Address : ");
                item.Zip = Console.ReadLine();
                //For having Valid Phone No
                while (true)
                {
                    Console.Write("New Phone Number : ");
                    item.PhoneNo = Console.ReadLine();
                    if (AddressBookDetailsValidation.Validate(item))
                    {
                        break;
                    }
                }
                //For having Valid Email
                while (true)
                {
                    Console.Write("New Email : ");
                    item.Email = Console.ReadLine();
                    if (AddressBookDetailsValidation.Validate(item))
                    {
                        break;
                    }
                }
                personFound = true;
                AddressBookDBWork.UpdateContactInDB(item);
                CustomPrint.PrintInRed("Details have been updated in " + addressBookName, false);
            }
            if (personFound == false)
            {
                CustomPrint.PrintInMagenta("Person not found");
            }
        }