Пример #1
0
        public void TestUpdating()
        {
            int id = logic.Add("Vyacheslav", "Soloviev", new DateTime(1995, 12, 27), 23,
                               "Samara", "Chapaeva", "22/24");

            Person person = logic.ShowById(id);

            person.Name = "Igor";

            logic.Update(id, "Igor", "Soloviev", new DateTime(1995, 12, 27), 23,
                         "Samara", "Chapaeva", "22/24");

            Assert.AreEqual(Person.ToString(logic.ShowById(id)), Person.ToString(person),
                            "Adding data about person incorrect");

            logic.Delete(id);
        }
        private static void Update()
        {
            Console.Clear();
            Console.WriteLine("Update menu: \n");

            Console.WriteLine("1. Update person");
            Console.WriteLine("2. Update medal");
            Console.WriteLine("3. To main menu");

            Console.Write("\nChoose menu item ");

            switch (Console.ReadKey().Key)
            {
            case ConsoleKey.D1:
            {
                Console.WriteLine("\n");
                Console.Write("Enter person's ID: ");
                int personID = int.Parse(Console.ReadLine());
                Console.Write("Enter person's name: ");
                string name = Console.ReadLine();
                Console.Write("Enter person's surname: ");
                string surname = Console.ReadLine();
                Console.Write("Enter person's date of birth: ");
                DateTime dateOfBirth = DateTime.Parse(Console.ReadLine());
                Console.Write("Enter person's age: ");
                int age = int.Parse(Console.ReadLine());
                Console.Write("Enter city of residence: ");
                string city = Console.ReadLine();
                Console.Write("Enter street's name: ");
                string street = Console.ReadLine();
                Console.Write("Enter house number: ");
                string houseNumber = Console.ReadLine();

                try
                {
                    personLogic.Update(personID, name, surname, dateOfBirth, age, city, street, houseNumber);
                    //personLogic.Update(6, "Vasya", "Ivanov", new DateTime(1996, 12, 27), 30, "Saratov", "Chapaeva", "47a");
                }
                catch (ArgumentNullException nullEx)
                {
                    Console.WriteLine($"\n{nullEx.Message}");
                    Console.WriteLine("Press any key for continue");
                    Console.ReadKey();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"\n{ex.Message}");
                    Console.WriteLine("Press any key for continue");
                    Console.ReadKey();
                }

                Start();
                break;
            }

            case ConsoleKey.D2:
            {
                Console.WriteLine("\n");
                Console.WriteLine("Enter medal's ID: ");
                int medalID = int.Parse(Console.ReadLine());
                Console.Write("Enter medal's title: ");
                string title = Console.ReadLine();
                Console.Write("Enter medal's material: ");
                string material = Console.ReadLine();


                try
                {
                    medalLogic.Update(medalID, title, material);
                    //medalLogic.Add(1, "For summer practice", null);
                }
                catch (ArgumentNullException nullEx)
                {
                    Console.WriteLine($"\n{nullEx.Message} \n ");
                    Console.WriteLine("Press any key for continue");
                    Console.ReadKey();
                }

                Start();
                break;
            }

            case ConsoleKey.D3:
            {
                Start();
                break;
            }

            default:
                return;
            }
        }
Пример #3
0
        private static void Update()
        {
            Console.Clear();
            Console.WriteLine("Update menu:\n" +
                              "1. Update person\n" +
                              "2. Update medal\n" +
                              "3. Go to the beginning");

            switch (Console.ReadKey().Key)
            {
            case ConsoleKey.D1:
            {
                Console.WriteLine();
                Console.Write("Id: ");
                int personId = int.Parse(Console.ReadLine());
                Console.Write("Name: ");
                string name = Console.ReadLine();
                Console.Write("Surname: ");
                string surname = Console.ReadLine();
                Console.Write("Date of birth: ");
                DateTime dateOfBirth = DateTime.Parse(Console.ReadLine());
                Console.Write("Age: ");
                int age = int.Parse(Console.ReadLine());
                Console.Write("City's name: ");
                string city = Console.ReadLine();
                Console.Write("Street's name: ");
                string street = Console.ReadLine();
                Console.Write("House number: ");
                string numberOfHouse = Console.ReadLine();

                try
                {
                    personLogic.Update(personId, name, surname, dateOfBirth, age, city, street, numberOfHouse);
                }
                catch (ArgumentNullException nullEx)
                {
                    Console.WriteLine($"\n{nullEx.Message}");
                    Console.WriteLine("Press any key for continue.");
                    Console.ReadKey();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"\n{ex.Message}");
                    Console.WriteLine("Press any key for continue.");
                    Console.ReadKey();
                }

                Start();
                break;
            }

            case ConsoleKey.D2:
            {
                Console.WriteLine();
                Console.WriteLine("Id: ");
                int medalId = int.Parse(Console.ReadLine());
                Console.Write("Name: ");
                string name = Console.ReadLine();
                Console.Write("Material: ");
                string material = Console.ReadLine();

                try
                {
                    medalLogic.Update(medalId, name, material);
                }
                catch (ArgumentNullException nullEx)
                {
                    Console.WriteLine($"\n{nullEx.Message} \n ");
                    Console.WriteLine("Press any key for continue.");
                    Console.ReadKey();
                }

                Start();
                break;
            }

            case ConsoleKey.D3:
            {
                Start();
                break;
            }

            default:
            {
                Console.WriteLine("\n\nInvalid input. Try again.");
                Thread.Sleep(2500);
                Start();
                break;
            }
            }
        }