public void TestAdding()
        {
            int id = logic.Add("For test", "Bronze");

            var medal = new Medal
            {
                Title    = "For test",
                Material = "Bronze"
            };

            Assert.AreEqual(Medal.ToString(logic.ShowById(id)), Medal.ToString(medal),
                            "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;
            }
        }
예제 #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;
            }
            }
        }