Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        public static void AddressBook()
        {
            Console.WriteLine("=========================================");
            Console.Write("Enter the new/saved Address Book Name : ");
            WorkingOnAddressBook addressBookObj = new WorkingOnAddressBook();

            addressBookObj.AddressBookName = Console.ReadLine();
            //Validates AddressBookName. Calls Address Book method if AddressBookName is null
            if (!AddressBookDetailsValidation.Validate(addressBookObj))
            {
                AddressBook();
            }
            WorkAddressBook(addressBookObj);
        }
Exemplo n.º 3
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");
            }
        }