Exemplo n.º 1
0
        /// <summary>
        /// Creates the address details.
        /// </summary>
        /// <param name="bookName">Name of the book.</param>
        /// <param name="firstName">The first name.</param>
        /// <param name="lastName">The last name.</param>
        /// <param name="address">The address.</param>
        /// <param name="city">The city.</param>
        /// <param name="state">The state.</param>
        /// <param name="zip">The zip.</param>
        /// <param name="phoneNumber">The phone number.</param>
        public static void CreateAddressDetails(string bookName, string firstName, string lastName, string address, string city, string state, string zip, string phoneNumber)
        {
            ////creating a object of addresDetails
            AddressDetails addressDetails = new AddressDetails(firstName, lastName, address, city, state, zip, phoneNumber);

            //// Getting the AddressBook and adding the newly created object in list.
            AddressBook addressBook = Input.GetBookDetails(bookName);

            addressBook.AddressDetailsList.Add(addressDetails);
            Input.WriteAddressBookToFile(addressBook);
            Console.WriteLine("Added to AddressBook " + bookName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Takes the input for address.
        /// </summary>
        /// <param name="bookName">Name of the book.</param>
        public static void TakeInputForAddress(string bookName)
        {
            string firstName   = string.Empty;
            string lastName    = string.Empty;
            string address     = string.Empty;
            string city        = string.Empty;
            string state       = string.Empty;
            string zip         = string.Empty;
            string phoneNumber = string.Empty;

            while (true)
            {
                Console.WriteLine("Enter the firstName");
                firstName = Console.ReadLine();

                ////check whether the user entered correct string
                if (!Regex.IsMatch(firstName, "^[a-zA-z]+$"))
                {
                    Console.WriteLine("Special Characters, numbers are not allowed...");
                    continue;
                }

                ////check whether the user entered correct string
                if (AddressDetails.DoesFileNameExist(bookName, firstName))
                {
                    Console.WriteLine("First name with" + firstName + " already exist, Please enter another name : ");
                }

                break;
            }

            while (true)
            {
                Console.WriteLine("Enter the LastName");
                lastName = Console.ReadLine();

                ////check whether the user entered correct string
                if (!Regex.IsMatch(lastName, "^[a-zA-z]+$"))
                {
                    Console.WriteLine("Special Characters, numbers are not allowed...");
                    continue;
                }

                break;
            }

            while (true)
            {
                Console.WriteLine("Enter the Address");
                address = Console.ReadLine();

                ////check whether the user entered correct string
                if (InventoryManagement.InventoryMngtUtility.CheckString(address))
                {
                    Console.WriteLine("Address can't be Empty...");
                    continue;
                }

                break;
            }

            while (true)
            {
                Console.WriteLine("Enter the City");
                city = Console.ReadLine();

                ////check whether the user entered correct string
                if (!Regex.IsMatch(city, "^[a-zA-z]+$"))
                {
                    Console.WriteLine("Special Characters,number not allowed...");
                    continue;
                }

                break;
            }

            while (true)
            {
                Console.WriteLine("Enter the State");
                state = Console.ReadLine();

                ////check whether the user entered correct string
                if (!Regex.IsMatch(state, "^[a-zA-z]+$"))
                {
                    Console.WriteLine("Special Characters, number are not allowed...");
                    continue;
                }

                break;
            }

            while (true)
            {
                Console.WriteLine("Enter the Zip");
                zip = Console.ReadLine();

                ////check whether the user entered correct input
                if (!Regex.IsMatch(zip, "^[0-9]+$"))
                {
                    Console.WriteLine("Characters not allowed...");
                    continue;
                }

                break;
            }

            while (true)
            {
                Console.WriteLine("Enter the 10 digit Contact Number");
                phoneNumber = Console.ReadLine();

                ////check whether the user entered correct input
                if (!Regex.IsMatch(phoneNumber, "^[0-9]{10}$"))
                {
                    Console.WriteLine("Characters are not allowed");
                    continue;
                }

                break;
            }

            ////call to the create method for address book and pass inputs taken by the user
            AddressDetails.CreateAddressDetails(bookName, firstName, lastName, address, city, state, zip, phoneNumber);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Edits the details.
        /// </summary>
        /// <param name="bookName">Name of the book.</param>
        public static void EditDetails(string bookName)
        {
            int    option     = 0;
            string nameToEdit = string.Empty;

            Console.WriteLine("Enter the First Name you want to edit");
            nameToEdit = Console.ReadLine();

            if (AddressDetails.DoesFileNameExist(nameToEdit, bookName) == false)
            {
                Console.WriteLine("The Name You Entered Does not Exist");
                return;
            }

            Console.WriteLine("------------------------------------------");
            AddressBook.PrintSingleAddresss(bookName, nameToEdit);
            Console.WriteLine("------------------------------------------");

            while (true)
            {
                Console.WriteLine("Choose what you want to edit");
                Console.WriteLine("0) To Go back");
                Console.WriteLine("1) Address");
                Console.WriteLine("2) City");
                Console.WriteLine("3) State");
                Console.WriteLine("4) Zip");
                Console.WriteLine("5) PhoneNumber");
                string stringOption = Console.ReadLine();

                if (InventoryManagement.InventoryMngtUtility.IsNumber(stringOption) == false)
                {
                    Console.WriteLine("Invalid Input");
                    continue;
                }

                option = Convert.ToInt32(stringOption);

                ////calling the methods based on the Option Choosen.
                switch (option)
                {
                case 0:
                {
                    return;
                }

                case 1:
                {
                    AddressDetailsManipulation.ChangeAddress(bookName, nameToEdit);
                    break;
                }

                case 2:
                {
                    AddressDetailsManipulation.ChangeCity(bookName, nameToEdit);
                    break;
                }

                case 3:
                {
                    AddressDetailsManipulation.ChangeState(bookName, nameToEdit);
                    break;
                }

                case 4:
                {
                    AddressDetailsManipulation.ChangeZip(bookName, nameToEdit);
                    break;
                }

                case 5:
                {
                    AddressDetailsManipulation.ChangePhoneNumber(bookName, nameToEdit);
                    break;
                }

                default:
                {
                    Console.WriteLine("Invalid Input");
                    break;
                }
                }
            }
        }