/// <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> /// Update Tester /// </summary> /// <param name="updatedTester">The Tester to update</param> public void UpdateTester(Tester updatedTester) { //check if tester is ok if (AllTesters.All(tester => tester.Id != updatedTester.Id)) { throw new Exception("tester doesn't exist"); } if (Tools.GetAge(updatedTester.BirthDate) < Configuration.MinTesterAge) { throw new Exception("The Tester is too young"); } if (updatedTester.Address == null) { throw new Exception("Need to know tester address"); } if (updatedTester.BirthDate == DateTime.MinValue) { throw new Exception("Invalid birth date"); } //add tester _dalImp.UpdateTester(updatedTester); }
/// <summary> /// Add a Tester /// </summary> /// <param name="newTester">The Tester to add</param> public void AddTester(Tester newTester) { //check if tester is ok if (AllTesters.Any(tester => tester.Id == newTester.Id)) { throw new Exception("Tester exist already"); } if (Tools.GetAge(newTester.BirthDate) < Configuration.MinTesterAge) { throw new Exception("The Tester is too young"); } if (newTester.Address == null) { throw new Exception("Need to know tester address"); } if (newTester.BirthDate == DateTime.MinValue) { throw new Exception("Invalid birth date"); } //add tester _dalImp.AddTester(newTester); }
/// <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); }