Ejemplo n.º 1
0
        public void TestAdding()
        {
            int id = logic.Add("Vyacheslav", "Soloviev", new DateTime(1995, 12, 27), 23,
                               "Samara", "Chapaeva", "22/24");

            var person = new Person
            {
                Name          = "Vyacheslav",
                Surname       = "Soloviev",
                DateOfBirth   = new DateTime(1995, 12, 27),
                Age           = 23,
                City          = "Samara",
                Street        = "Chapaeva",
                NumberOfHouse = "22/24"
            };

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

            logic.Delete(id);
        }
        private static void Delete()

        {
            Console.Clear();

            Console.WriteLine("Delete menu: \n");

            Console.WriteLine("1. Delete person");
            Console.WriteLine("2. Delete medal");
            Console.WriteLine("3. Delete reward");
            Console.WriteLine("4. 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());

                try
                {
                    personLogic.Delete(personID);
                }
                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.Write("Enter medal's ID: ");
                int medalID = int.Parse(Console.ReadLine());

                try
                {
                    medalLogic.Delete(medalID);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"\n{ex.Message}");
                    Console.WriteLine("Press any key for continue");
                    Console.ReadKey();
                }

                Start();
                break;
            }

            case ConsoleKey.D3:
            {
                Console.WriteLine("\n");
                Console.Write("Enter person's ID: ");
                int personID = int.Parse(Console.ReadLine());
                Console.Write("Enter medal's ID: ");
                int medalID = int.Parse(Console.ReadLine());

                try
                {
                    personLogic.DeleteReward(personID, medalID);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"\n{ex.Message}");
                    Console.WriteLine("Press any key for continue");
                    Console.ReadKey();
                }

                Start();
                break;
            }

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

            default:
                return;
            }
        }
Ejemplo n.º 3
0
        private static void Delete()
        {
            Console.Clear();
            Console.WriteLine("Delete menu:\n" +
                              "1. Delete person\n" +
                              "2. Delete medal\n" +
                              "3. Delete reward\n" +
                              "4. Go to the beginning.");

            switch (Console.ReadKey().Key)
            {
            case ConsoleKey.D1:
            {
                Console.WriteLine();
                Console.Write("Id: ");
                int personId = int.Parse(Console.ReadLine());

                try
                {
                    personLogic.Delete(personId);
                }
                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.Write("Id: ");
                int medalId = int.Parse(Console.ReadLine());

                try
                {
                    medalLogic.Delete(medalId);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"\n{ex.Message}");
                    Console.WriteLine("Press any key for continue.");
                    Console.ReadKey();
                }

                Start();
                break;
            }

            case ConsoleKey.D3:
            {
                Console.WriteLine();
                Console.Write("Person's id: ");
                int personId = int.Parse(Console.ReadLine());
                Console.Write("Medal's id: ");
                int medalId = int.Parse(Console.ReadLine());

                try
                {
                    rewardLogic.Delete(personId, medalId);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"\n{ex.Message}");
                    Console.WriteLine("Press any key for continue.");
                    Console.ReadKey();
                }

                Start();
                break;
            }

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

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