Esempio n. 1
0
        public void EditContact(int cur)
        {
            Console.WriteLine("Введите новое значение для поля, если хотите его изменить:");
            Console.WriteLine("Фамилия:");
            string surname = Console.ReadLine();

            Console.WriteLine("Имя");
            string name = Console.ReadLine();

            Console.WriteLine("Отчество:");
            string patronymic = Console.ReadLine();

            Console.WriteLine("Номер:");
            string number = Console.ReadLine();

            Console.WriteLine("Страна:");
            string country = Console.ReadLine();

            Console.WriteLine("Дата рождения:");
            string birthday = Console.ReadLine();

            Console.WriteLine("Организация:");
            string organization = Console.ReadLine();

            Console.WriteLine("Должность:");
            string position = Console.ReadLine();

            Console.WriteLine("Прочие заметки");
            string other = Console.ReadLine();

            HumanContact newContact = new HumanContact(surname, name, number, country, patronymic, birthday, organization, position, other);

            if (newContact.Surname == "")
            {
                newContact.Surname = book[cur].Surname;
            }
            if (newContact.Name == "")
            {
                newContact.Name = book[cur].Name;
            }
            if (newContact.Patronymic == "")
            {
                newContact.Patronymic = book[cur].Patronymic;
            }
            if (newContact.Number == "")
            {
                newContact.Number = book[cur].Number;
            }
            if (newContact.Country == "")
            {
                newContact.Country = book[cur].Country;
            }
            if (newContact.Birthday == "")
            {
                newContact.Birthday = book[cur].Birthday;
            }
            if (newContact.Position == "")
            {
                newContact.Position = book[cur].Position;
            }
            if (newContact.Other == "")
            {
                newContact.Other = book[cur].Other;
            }

            HumanContactIsValid check = new HumanContactIsValid(newContact);

            if (check.AllIsValid())
            {
                book[cur] = newContact;
                Console.WriteLine("Контакт успешно изменен");
            }
            else
            {
                Console.WriteLine("Контакт не изменен по причине некорректно введенных данных");
            }
        }
Esempio n. 2
0
        public void AddContact()
        {
            Console.WriteLine("Фамилия:");
            string surname = Console.ReadLine();

            Console.WriteLine("Имя");
            string name = Console.ReadLine();

            Console.WriteLine("Отчество:");
            string patronymic = Console.ReadLine();

            Console.WriteLine("Номер:");
            string number = Console.ReadLine();

            Console.WriteLine("Страна:");
            string country = Console.ReadLine();

            Console.WriteLine("Дата рождения:");
            string birthday = Console.ReadLine();

            Console.WriteLine("Организация:");
            string organization = Console.ReadLine();

            Console.WriteLine("Должность:");
            string position = Console.ReadLine();

            Console.WriteLine("Прочие заметки");
            string other = Console.ReadLine();

            if (surname == "" || name == "" || number == "" || country == "")
            {
                Console.WriteLine("Новый контакт не добавлен по причине некорректно введенных данных");
            }
            else
            {
                if (patronymic == "")
                {
                    patronymic = null;
                }
                if (birthday == "")
                {
                    birthday = null;
                }
                if (organization == "")
                {
                    organization = null;
                }
                if (other == "")
                {
                    other = null;
                }
                HumanContact        contact = new HumanContact(surname, name, number, country, patronymic, birthday, organization, position, other);
                HumanContactIsValid check   = new HumanContactIsValid(contact);
                if (check.AllIsValid())
                {
                    book.Add(contact);
                    Console.WriteLine("Новый контакт успешно добавлен");
                }
                else
                {
                    Console.WriteLine("Новый контакт не добавлен по причине некорректно введенных данных");
                }
            }
        }