public void AddSwimmwer()
        {
            Console.Write("Enter Swimmer name:");
            string swimmerName = Console.ReadLine();

            while (!IsAllAlphabetic(swimmerName))
            {
                Console.WriteLine("Incorrect Name! Try again");
                swimmerName = Console.ReadLine();
            }

            Console.Write("Enter Swimmer surname:");
            string swimmerSurname = Console.ReadLine();

            while (!IsAllAlphabetic(swimmerSurname))
            {
                Console.WriteLine("Incorrect Surname! Try again");
                swimmerSurname = Console.ReadLine();
            }

            Console.Write("Enter Swimmer age:");
            string age = Console.ReadLine();
            int    tryint;

            while ((!int.TryParse(age, out tryint)) || (!AgeValidationAttribute.IsValidSwimmerAge(Convert.ToInt32(age))))
            {
                Console.WriteLine("Incorrect Age! Try again ");
                age = Console.ReadLine();
            }

            Console.Write("Enter Coach Id:");
            string swimmerCoachId = Console.ReadLine();

            while (!int.TryParse(swimmerCoachId, out tryint))
            {
                Console.WriteLine("Incorrect Id! Try again ");
                swimmerCoachId = Console.ReadLine();
            }

            try
            {
                Swimmer swimmer = new Swimmer {
                    FirstName = swimmerName, LastName = swimmerSurname, Age = Convert.ToInt32(age), CoachId = Convert.ToInt32(swimmerCoachId)
                };
                using (swimmingContext swimdb = new swimmingContext())
                {
                    ISwimmerManager <Swimmer> swimmerManager = new SwimmerRepository(swimdb);
                    swimmerManager.Add(swimmer);
                    Console.WriteLine("Swimmer is added");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public void Attribute_AgeValidation_IsValid(int age)
        {
            var result = AgeValidationAttribute.IsValidSwimmerAge(age);

            Assert.AreEqual(result, false);
        }