示例#1
0
        // Paprasti metodai - jokios logikos.
        // Add metodas - prideti kontakta
        public static void AddContact()
        {
            List <Contact> existingContacts;

            // Deserialize metodas
            existingContacts = Contact.DeserializeForAddition(path);

            Console.WriteLine("-- Enter your Name: ", "\n");
            var input_name = Console.ReadLine();

            Console.WriteLine("-- Enter your Last Name: ", "\n");
            var input_lastName = Console.ReadLine();

            Console.WriteLine("-- Enter your phone number: ", "\n");
            string phoneNumberAsString = Console.ReadLine();


            // Patikrinimai - ar skaicius, ar unikalus

            int input_phoneNumber = CheckIfNumber(phoneNumberAsString);

            Console.WriteLine(input_phoneNumber);
            bool check = CheckUniqueness(existingContacts, input_phoneNumber);

            if (check == true)
            {
                Console.WriteLine("Number already exists. Please enter new one.");
                phoneNumberAsString = Console.ReadLine();
                input_phoneNumber   = CheckIfNumber(phoneNumberAsString);
            }

            Console.WriteLine("-- Enter your address: ", "\n");
            var input_address = Console.ReadLine();

            // Objekto sukurimas
            var contactToAdd = new Contact
            {
                Name        = input_name,
                LastName    = input_lastName,
                PhoneNumber = input_phoneNumber,
                Address     = input_address
            };


            // Pridedame kontakta i lista
            existingContacts.Add(contactToAdd);

            // Iškviecamas Serialize metodas
            Contact.Serialize(path, existingContacts);
        }