/// <summary>
 ///     Remove Trainee
 /// </summary>
 /// <param name="traineeToDelete">The Trainee to remove</param>
 public void RemoveTrainee(Trainee traineeToDelete)
 {
     if (AllTrainees.All(trainee => trainee.Id != traineeToDelete.Id))
     {
         throw new Exception("Trainee doesn't exist");
     }
     if (AllTests.Any(x => x.TraineeId == traineeToDelete.Id))
     {
         throw new Exception("Trainee Has " + AllTests.Count(x => x.TraineeId == traineeToDelete.Id) +
                             " Tests. Please Delete Them First.");
     }
     _dalImp.RemoveTrainee(traineeToDelete);
 }
 /// <summary>
 ///     Remove a Tester
 /// </summary>
 /// <param name="testerToDelete">The Tester to remove</param>
 public void RemoveTester(Tester testerToDelete)
 {
     if (AllTesters.All(tester => tester.Id != testerToDelete.Id))
     {
         throw new Exception("Tester doesn't exist");
     }
     if (AllTests.Any(x => x.TesterId == testerToDelete.Id))
     {
         throw new Exception("Tester Has " + AllTests.Count(x => x.TesterId == testerToDelete.Id) +
                             " Tests. Please Delete Them First.");
     }
     _dalImp.RemoveTester(testerToDelete);
 }
        /// <summary>
        ///     Add a Test
        /// </summary>
        /// <param name="newTest">The Test to add</param>
        public void AddTest(Test newTest)
        {
            //check if the test is ok
            var testMissingDate = newTest.TestTime == DateTime.MinValue;

            var testerExist = AllTesters.Any(tester => tester.Id == newTest.TesterId);

            var traineeExist = AllTrainees.Any(trainee => trainee.Id == newTest.TraineeId);

            var twoTestesTooClose = AllTests.Any(test =>
                                                 test.TraineeId == newTest.TraineeId && test.LicenseType == newTest.LicenseType &&
                                                 Math.Abs((newTest.TestTime - test.TestTime).TotalDays) < Configuration.MinTimeBetweenTests);

            // the trainee didn't the minimum number of lessens before test
            var lessThenMinLessons = AllTrainees.Any(trainee =>
                                                     trainee.Id == newTest.TraineeId && trainee.LicenseTypeLearning.Any(l =>
                                                                                                                        l.License == newTest.LicenseType && l.NumberOfLessons < Configuration.MinLessons));

            var traineeIsLearningLicense = AllTrainees.Any(trainee =>
                                                           trainee.Id == newTest.TraineeId &&
                                                           trainee.LicenseTypeLearning.Any(l => l.License == newTest.LicenseType));

            var testerIsTeachingLicense = AllTesters.Any(tester =>
                                                         tester.Id == newTest.TesterId && tester.LicenseTypeTeaching.Any(l => l == newTest.LicenseType));

            var tooManyTestInWeek =
                AllTests.Count(test =>
                               test.TesterId == newTest.TesterId && Tools.DatesAreInTheSameWeek(newTest.TestTime, test.TestTime)) +
                1 >
                AllTesters.First(tester => tester.Id == newTest.TesterId).MaxWeekExams;

            var traineeHasTestInSameTime = AllTests.Any(test =>
                                                        test.TraineeId == newTest.TraineeId && newTest.TestTime == test.TestTime);
            var testerHasTestInSameTime =
                AllTests.Any(test => test.TesterId == newTest.TesterId && newTest.TestTime == test.TestTime);

            var traineeHasLicenseAlready = AllTests.Any(y =>
                                                        y.TraineeId == newTest.TraineeId && y.Passed == true && y.LicenseType == newTest.LicenseType);

            var traineePassedTestAlready = AllTests.Any(test =>
                                                        test.TraineeId == newTest.TraineeId && test.LicenseType == newTest.LicenseType && test.Passed == true);

            if (testMissingDate)
            {
                throw new Exception("Enter a valid date");
            }
            if (tooManyTestInWeek)
            {
                throw new Exception("To many tests for tester");
            }
            if (!traineeExist)
            {
                throw new Exception("This trainee doesn't exist");
            }
            if (!testerExist)
            {
                throw new Exception("This tester doesn't exist");
            }
            if (twoTestesTooClose)
            {
                throw new Exception(
                          "The trainee has a already a test in " + Configuration.MinTimeBetweenTests + " days");
            }
            if (lessThenMinLessons)
            {
                throw new Exception("The trainee learned less then " + Configuration.MinLessons +
                                    " lessons which is the minimum");
            }
            if (!traineeIsLearningLicense)
            {
                throw new Exception("The trainee is not learning for this license");
            }
            if (!testerIsTeachingLicense)
            {
                throw new Exception("Tester is not qualified for this license type");
            }
            if (traineeHasTestInSameTime)
            {
                throw new Exception("The trainee has already another test in the same time");
            }
            if (testerHasTestInSameTime)
            {
                throw new Exception("The tester has already another test in the same time");
            }
            if (traineeHasLicenseAlready)
            {
                throw new Exception("The trainee has already a license with same type");
            }
            if (traineePassedTestAlready)
            {
                throw new Exception("The trainee already passed the test");
            }


            //add the test
            _dalImp.AddTest(newTest);
        }