Пример #1
0
        public bool AddTest(Test test, List <Tester> validTesters)
        {
            if (dal.searchTrainee(test.Id_trainee) == null)
            {
                throw new Exception("Trainee was not found in the system");
            }
            int index = checkTheKind(test.Id_trainee, test);

            if (!numLessonsValid(test.Id_trainee, index))
            {
                throw new Exception("Trainee's number of lessons is less than the minimum");
            }
            if (isPassAlready(test.Id_trainee, index))
            {
                throw new Exception("The trainee has already licence on this kind of vehicle");
            }
            if (Validation.IsDateValid(test.TestDate))
            {
                throw new Exception("Date is not valid !");
            }
            if (!isRangeTestValid(test))
            {
                throw new Exception("Seven days have not passed from the last test yet");
            }
            if (!isTraineeAvailable(test.Id_trainee, test.TestDate))
            {
                throw new Exception("HONEY CHECK YOUR SCHEDULE !");
            }

            test.Id_tester = FindTester(test.TestDate, test.TestHour, test.VehicleKind, validTesters); //  חיפוש מורה פנוי ועדכון שמו בטסט
            if (test.Id_tester == null)                                                                //אם לא מצאנו טסטר פנוי
            {
                return(false);
            }
            //  Tester t =dal.searchTester(test.Id_tester);//הוספת הטסט לרשימת הטסטים של המורה
            test.Code = Configuration.testCode;
            // t.TestsOfTester.Add(test);
            addTestToTester(test.Id_tester, test);
            dal.AddTest(test);
            //Configuration.testCode++;

            return(true);
        }