예제 #1
0
 public static void AcquireSurnameAndName(out string surname, out string name)
 {
     string[] surnameAndName = UserDialog.AcquireStringsFormated(
         new string[] { "surname", "name" }, PhoneBook.NameFilter, "letters only");
     surname = surnameAndName[0];
     name    = surnameAndName[1];
 }
예제 #2
0
        public IReadOnlyList <Tuple <int, PhoneBook.Note> > AcquireNotesByNameOrPhone(bool isEscapeAllowed)
        {
            UserDialog.DisplayOptions(nameOrPhoneMenu, "Enter option", isEscapeAllowed ? "To escape" : null);
            IReadOnlyList <Tuple <int, PhoneBook.Note> > notes = null;

            switch (UserDialog.AcquireCommandInRange(0, 1, isEscapeAllowed))
            {
            case ESCAPE_VAL:
                notes = null;
                break;

            case 0:
                string surname;
                string name;
                AcquireSurnameAndName(out surname, out name);
                notes = phoneBook.GetNotes(surname, name);
                break;

            case 1:
                string phoneNumber = AcquirePhoneNumberToCheck();
                notes = phoneBook.GetNotes(phoneNumber);
                break;
            }
            return(notes);
        }
예제 #3
0
        private void EditNote()
        {
            Console.WriteLine("Editing existing note..");
            var notes = AcquireNotesByNameOrPhone(true);

            if (notes == null)
            {
                UserDialog.DisplayEscapeMsg();
                return;
            }
            if (notes.Count == 0)
            {
                UserDialog.DisplayNoMatchMsg();
                return;
            }
            if (notes.Count > 1)
            {
                notes = AcquireNoteOfEqual(notes, true);
                if (notes == null)
                {
                    return;
                }
            }
            EditNoteInfo(notes[0]);
        }
예제 #4
0
        private void AddNote()
        {
            Console.WriteLine("Adding new note...");
            string surname;
            string name;

            AcquireSurnameAndName(out surname, out name);
            var notes = phoneBook.GetNotes(surname, name);

            if (notes != null && notes.Count == 1)
            {
                if (!UserDialog.AcquireYesOrNo("One Note with the same Name and Surname already exists\nDo you want to create new?"))
                {
                    if (UserDialog.AcquireYesOrNo("Do you want to Edit existing?"))
                    {
                        EditNoteInfo(notes[0]);
                    }
                    return;
                }
            }
            else if (notes != null && notes.Count > 1)
            {
                if (!UserDialog.AcquireYesOrNo("There are several Notes with the same Name and Surname\nDo you want to create new?"))
                {
                    if (UserDialog.AcquireYesOrNo("Do you want to Edit one of existing?"))
                    {
                        EditNoteInfo(AcquireNoteOfEqual(notes, false).ElementAt(0));
                    }
                    return;
                }
            }
            /*creating new note*/
            PhoneBook.Note newNote = new PhoneBook.Note()
            {
                name = name, surname = surname, phoneNumber = AcquirePhoneNumberToAdd()
            };
            EditNote(newNote);
            if (PhoneBook.Result.Success != phoneBook.InsertNote(newNote))
            {
                throw new Exception("Insert Note error while adding");
            }
        }
예제 #5
0
        public string AcquirePhoneNumberToAdd() // acceptes only not existing numbers
        {
            string pn     = null;
            string filler = "";

            while (true)
            {
                pn = UserDialog.AcquireStringFormated(filler + "phone number",
                                                      PhoneBook.PhoneNumberFilter, "digits only");
                if (phoneBook.Exists(pn))
                {
                    Console.WriteLine("This phone number already exists. Impossible to add");
                    filler = "another ";
                }
                else
                {
                    break;
                }
            }
            return(pn);
        }
예제 #6
0
        public IReadOnlyList <Tuple <int, PhoneBook.Note> > AcquireNoteOfEqual(IReadOnlyList <Tuple <int, PhoneBook.Note> > notes, bool isEscapeAllowed)
        {
            if (notes == null)
            {
                throw new ArgumentOutOfRangeException("not allowed to send null list");
            }
            Console.WriteLine("List contains several equal Notes:");
            DisplayShortInfo(notes);
            Console.Write("Enter ID to perform action ");
            if (isEscapeAllowed)
            {
                Console.Write($"or {ESCAPE_VAL} to escape");
            }
            Console.WriteLine();
            int idx = UserDialog.AcquireCommandInRange(notes.First().Item1, notes.Last().Item1, isEscapeAllowed);

            if (idx == ESCAPE_VAL)
            {
                return(null);
            }
            return(notes.Where(x => x.Item1 == idx).ToList());
        }
예제 #7
0
 public string AcquirePhoneNumberToCheck()
 {
     return(UserDialog.AcquireStringFormated("phone number",
                                             PhoneBook.PhoneNumberFilter, "digits only"));
 }