/// <summary> /// Function that adds a given tester to the system /// </summary> /// <param name="NewTester">Tester to add to the system</param> public void AddTester(Tester NewTester) { if (NewTester.Age() > Configuration.MaximumTesterAge) { throw new Exception("Tester is too old."); } if (NewTester.Age() < Configuration.MinimumTesterAge) { throw new Exception("Tester is too young."); } int Sum = 0; int Temp = int.Parse(NewTester.IDNumber) / 10; for (int i = 0; i < 8; i++) { Sum += (Temp % 10) * (Utilities.FuncForID(i)) / 10 + ((Temp % 10) * Utilities.FuncForID(i)) % 10; Temp /= 10; } Temp = (((Sum / 10) * 10 + 10) - Sum) % 10; if (Temp != int.Parse(NewTester.IDNumber) % 10) { throw new Exception("The ID number is not valid."); } try { FactoryDAL.Instance.AddTester(NewTester); } catch (Exception ex) { throw ex; } }
/// <summary> /// Function to update a Tester in the system /// </summary> /// <param name="updatedTester">Tester to be updated</param> public void UpdateTester(Tester updatedTester) { Tester tester = (from t in ReturnTesters() where t.IDNumber == updatedTester.IDNumber select t).FirstOrDefault(); List <Test> testList = new List <Test>(); try { testList = ReturnTests(); } catch { testList = new List <Test>(); } var k = (from t in testList where t.TesterId == updatedTester.IDNumber select t); if (tester == null) { throw new Exception("Tester does not exist."); } if (tester.TestsSignedUpFor > updatedTester.MaximumWeeklyTests) { throw new Exception(tester.Name.ToString() + " is already signed up to more tests then will be possible. Please manually cancel those tests before changing the amount of tests possible.\n At least " + (tester.TestsSignedUpFor - updatedTester.MaximumWeeklyTests).ToString() + " will need to be canceled to allow this action."); } if (/*tester.MyVehicles != updatedTester.MyVehicles && tester.MyVehicles != updatedTester.MyVehicles && */ k.Any(t => updatedTester.hasVehicle(t.TestVehicle) == false)) { throw new Exception(tester.Name.ToString() + " is signed up to tests they will not be able to do because they will no longer specialize in the needed vehicle.\n Please manually cancel those tests before updating the tester."); } if ((tester.MaxDistanceFromTest > updatedTester.MaxDistanceFromTest || tester.MyAddress != updatedTester.MyAddress) && k.Any(t => CalcDistance(updatedTester.MyAddress, t.AddressOfDeparture) > updatedTester.MaxDistanceFromTest)) { throw new Exception(tester.Name.ToString() + " is signed up to tests they will not be able to do because their address will be too far from the test.\n Please manually cancel those tests before updating the tester."); } if (updatedTester.Age() > Configuration.MaximumTesterAge) { throw new Exception(tester.Name.ToString() + " is too old."); } if (updatedTester.Age() < Configuration.MinimumTesterAge) { throw new Exception(tester.Name.ToString() + " is too young."); } //if (k.Any(t => !updatedTester.hasTestByDate(t.DateAndTime))) //{ // throw new Exception(tester.Name.ToString() + " is signed up to Tests that need to be canceled in order to change their schedule."); //} try { FactoryDAL.Instance.UpdateTester(updatedTester); } catch (Exception ex) { throw ex; } }