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 Add()
        {
            Console.Clear();
            Console.WriteLine("Add menu: \n");
            Console.WriteLine("1. Add new person");
            Console.WriteLine("2. Add new medal");
            Console.WriteLine("3. Add new 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 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.Add(name, surname, dateOfBirth, age, city, street, houseNumber);
                    //personLogic.Add("Ivan", "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.Write("Enter medal's title: ");
                string title = Console.ReadLine();
                Console.Write("Enter medal's material: ");
                string material = Console.ReadLine();


                try
                {
                    medalLogic.Add(title, material);
                    //medalLogic.Add("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:
            {
                Console.WriteLine("\n");

                Console.Write("Enter person's ID: ");
                int personID = int.Parse(Console.ReadLine());
                Console.Write("Enter meadl's ID: ");
                int medalID = int.Parse(Console.ReadLine());

                try
                {
                    personLogic.AddReward(personID, medalID);
                    //personLogic.Add(1, 1);
                }
                catch (ArgumentNullException nullEx)
                {
                    Console.WriteLine($"\n{nullEx.Message} \n ");
                    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 Add()
        {
            Console.Clear();
            Console.WriteLine("Add menu:\n" +
                              "1. Add new person\n" +
                              "2. Add new medal\n" +
                              "3. Add new reward\n" +
                              "4. Go to the beginning");

            switch (Console.ReadKey().Key)
            {
            case ConsoleKey.D1:
            {
                Console.WriteLine();
                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("Number of house: ");
                string numberOfHouse = Console.ReadLine();

                try
                {
                    personLogic.Add(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.Write("Name: ");
                string name = Console.ReadLine();
                Console.Write("Material: ");
                string material = Console.ReadLine();

                try
                {
                    medalLogic.Add(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:
            {
                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.Add(personId, medalId);
                }
                catch (ArgumentNullException nullEx)
                {
                    Console.WriteLine($"\n{nullEx.Message} \n ");
                    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;
            }
            }
        }