Ejemplo n.º 1
0
        /// <summary>
        /// It Create the New Address Book Data
        /// </summary>
        public void CreateAddressBook()
        {
            try
            {
                string name, mobileNumber, emailId, address, zip;

                name         = AddressBookValidation.NameValidation();
                mobileNumber = AddressBookValidation.MobileNumberValidation();
                emailId      = AddressBookValidation.EmailValidation();
                address      = AddressBookValidation.AddressValidation();
                zip          = AddressBookValidation.ZipValidation();

                CreateAddressBook createAddressBook = new CreateAddressBook
                {
                    Name         = name,
                    MobileNumber = mobileNumber,
                    EmailId      = emailId,
                    Address      = address,
                    Zip          = zip
                };

                List <CreateAddressBook> addressBooks = Utility.ReadAddressBookJson();
                addressBooks.Add(createAddressBook);
                Utility.SaveAddressBookInJson(addressBooks);
            }
            catch (Exception e)
            {
                Console.WriteLine("Message: {0}", e.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// It Edit the Specificed Data Address Book Data
        /// </summary>
        public void EditAddressBook()
        {
            try
            {
                List <CreateAddressBook> addressBooks = Utility.ReadAddressBookJson();

                if (addressBooks.Count == 0)
                {
                    Console.WriteLine("No Data Present in Address Book.");
                    return;
                }

                Utility.DisplayAddressBookData(addressBooks);

                int    choice, count;
                bool   inputFlag;
                string name = null, mobileNumber = null, email = null, address = null, zip = null;
                bool   flag;
                do
                {
                    Console.WriteLine();
                    Console.Write("Please Choose which Contact you want to Edit: ");
                    flag = int.TryParse(Console.ReadLine(), out choice);
                    if (choice <= 0 || choice > addressBooks.Count)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Invalid Choice");
                        Console.WriteLine();
                        Utility.DisplayAddressBookData(addressBooks);
                        flag = false;
                    }
                } while (!flag);

                count = 1;

                foreach (CreateAddressBook addressBook in addressBooks)
                {
                    if (count == choice)
                    {
                        name         = addressBook.Name;
                        mobileNumber = addressBook.MobileNumber;
                        email        = addressBook.EmailId;
                        address      = addressBook.Address;
                        zip          = addressBook.Zip;
                        break;
                    }
                    count++;
                }
                flag = false;
                count--;

                do
                {
                    do
                    {
                        Console.WriteLine();
                        Console.WriteLine("Details for the Selected Address are: ");
                        Console.WriteLine("1. Name: {0}", name);
                        Console.WriteLine("2. Mobile Number: {0}", mobileNumber);
                        Console.WriteLine("3. Email: {0}", email);
                        Console.WriteLine("4. Address: {0}", address);
                        Console.WriteLine("5. Zip: {0}", zip);
                        Console.WriteLine("6. Exit");
                        Console.Write("Enter Your Choice: ");
                        inputFlag = int.TryParse(Console.ReadLine(), out choice);
                        Utility.ErrorMessage(inputFlag);
                    } while (!inputFlag);
                    Console.WriteLine();
                    string tempData;
                    switch (choice)
                    {
                    case 1:
                        do
                        {
                            tempData = AddressBookValidation.NameValidation();
                            Utility.AddressBookErrorMessage(inputFlag, "Name");
                        } while (!inputFlag);
                        if (Utility.ConfirmChange())
                        {
                            name = tempData;
                            addressBooks[count].Name = name;
                            Utility.SaveAddressBookInJson(addressBooks);
                            Console.WriteLine("Your Name Has Been Successfully Updated. !!");
                        }
                        else
                        {
                            addressBooks[count].Name = name;
                        }
                        break;

                    case 2:
                        do
                        {
                            tempData = AddressBookValidation.MobileNumberValidation();
                            Utility.AddressBookErrorMessage(inputFlag, "Mobile Number");
                        } while (!inputFlag);
                        if (Utility.ConfirmChange())
                        {
                            mobileNumber = tempData;
                            addressBooks[count].MobileNumber = mobileNumber;
                            Utility.SaveAddressBookInJson(addressBooks);
                            Console.WriteLine("Your Mobile Number Has Been Successfully Updated. !!");
                        }
                        else
                        {
                            addressBooks[count].MobileNumber = mobileNumber;
                        }

                        break;

                    case 3:
                        do
                        {
                            tempData = AddressBookValidation.EmailValidation();
                            Utility.AddressBookErrorMessage(inputFlag, "Email-Id");
                        } while (!inputFlag);
                        if (Utility.ConfirmChange())
                        {
                            email = tempData;
                            addressBooks[count].EmailId = email;
                            Utility.SaveAddressBookInJson(addressBooks);
                            Console.WriteLine("Your Email-Id Has Been Successfully Updated. !!");
                        }
                        else
                        {
                            addressBooks[count].EmailId = email;
                        }

                        break;

                    case 4:
                        do
                        {
                            tempData = AddressBookValidation.AddressValidation();
                            Utility.AddressBookErrorMessage(inputFlag, "Address");
                        } while (!inputFlag);
                        if (Utility.ConfirmChange())
                        {
                            address = tempData;
                            addressBooks[count].Address = address;
                            Utility.SaveAddressBookInJson(addressBooks);
                            Console.WriteLine("Your Address Has Been Successfully Updated. !!");
                        }
                        else
                        {
                            addressBooks[count].Address = address;
                        }
                        break;

                    case 5:
                        do
                        {
                            tempData = AddressBookValidation.ZipValidation();
                            Utility.AddressBookErrorMessage(inputFlag, "Zip");
                        } while (!inputFlag);
                        if (Utility.ConfirmChange())
                        {
                            zip = tempData;
                            addressBooks[count].Zip = zip;
                            Utility.SaveAddressBookInJson(addressBooks);
                            Console.WriteLine("Your Zip Has Been Successfully Updated. !!");
                        }
                        else
                        {
                            addressBooks[count].Zip = zip;
                        }
                        break;

                    case 6:
                        flag = true;
                        break;

                    default:
                        Console.WriteLine("Invalid Choice. !!!");
                        break;
                    }
                } while (!flag);
            }
            catch (Exception e)
            {
                Console.WriteLine("Message: {0}", e.Message);
            }
        }