Example #1
0
        public void CommandEdit()
        {
            int    id     = (int)console.ReadLong("id:");
            Record record = recordManager.GetRecordByIdOrNull(id);

            if (record != null)
            {
                record.PrintFullInfo();
                while (true)
                {
                    Console.WriteLine("Enter number of field to edit ('0' to stop editing)");
                    Console.WriteLine();
                    Console.WriteLine("1. Lastname");
                    Console.WriteLine("2. Firstname");
                    Console.WriteLine("3. Patronymic");
                    Console.WriteLine("4. Phone number");
                    Console.WriteLine("5. Country");
                    Console.WriteLine("6. Birth date");
                    Console.WriteLine("7. Organization");
                    Console.WriteLine("8. Position");
                    Console.WriteLine("9. Other notes");
                    Console.WriteLine();

                    int field;
                    while (true)
                    {
                        field = (int)console.ReadLong("field:");
                        if (field < 0 || field > 9)
                        {
                            Console.WriteLine("Invalid number");
                            Console.WriteLine("Try again");
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (field == 0)
                    {
                        record.PrintFullInfo();
                        Console.WriteLine("Changes saved");
                        Console.WriteLine();
                        return;
                    }

                    switch (field)
                    {
                    case 1:
                        record.LastName = console.ReadNotEmptyString("Last name:");
                        break;

                    case 2:
                        record.FirstName = console.ReadNotEmptyString("First name:");
                        break;

                    case 3:
                        record.Patronymic = console.ReadStringOrNullIfEmpty("Patronymic (optional):");
                        break;

                    case 4:
                        record.PhoneNumber = console.ReadPhoneNumber("Phone number:");
                        break;

                    case 5:
                        record.Country = console.ReadNotEmptyString("Country:");
                        break;

                    case 6:
                        record.BirthDate = console.ReadDateTimeOrEmpty("Birth date (dd.MM.yyyy) (optional)");
                        break;

                    case 7:
                        record.Organization = console.ReadStringOrNullIfEmpty("Organization (optional):");
                        break;

                    case 8:
                        record.Position = console.ReadStringOrNullIfEmpty("Position (optional):");
                        break;

                    case 9:
                        record.OtherNotes = console.ReadStringOrNullIfEmpty("Other notes (optional):");
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine("Record not found :(");
            }
        }