コード例 #1
0
        public void AddFutureTest(Tester tester, Trainee trainee, DateTime time, Address address)
        {
            if (dal.GetTesterByID(tester.Id) == null)
            {
                throw new Exception(string.Format("tester {0} not exists in the DB.", tester.Id));
            }
            if (dal.GetTraineeById(trainee.Id) == null)
            {
                throw new Exception(string.Format("trainee {0} not exists in the DB.", trainee.Id));
            }
            if (DateTime.Now > time)
            {
                throw new Exception("you cant set future test for the past.");
            }
            var WeeklyTests = new List <Test>(from test in GetTestsByTesters(tester)
                                              let TestDiff = (7 + test.RealDateOfTest.DayOfWeek - DayOfWeek.Sunday) % 7
                                                             let TimeDiff = (7 + time.DayOfWeek - DayOfWeek.Sunday) % 7
                                                                            where time.AddDays(TimeDiff * -1).Date == test.DateOfTest.AddDays(TestDiff * -1).Date
                                                                            select test);

            if (WeeklyTests.Count > tester.MaxWeeklyTests)
            {
                throw new Exception(string.Format("The tester {0} can't have a test at {1} due to hte fact he exceded the maximum amount of tests that week", tester.ToString(), time.ToString()));
            }
            if (GetTestsByTrainee(trainee).Any(test => test.DateOfTest > DateTime.Now || test.RealDateOfTest != null))
            {
                throw new Exception(string.Format("You can not set a test for a student {0} because in the system already have a future test", trainee.Id));
            }

            var NumberOfTestsInTimeSpan = new List <Test>(from test in GetTestsByTesters(tester)
                                                          let timespan = test.RealDateOfTest - time
                                                                         where timespan.Duration().Minutes < 30
                                                                         select test);

            foreach (var test in GetTestsByTesters(tester))
            {
                if ((test.DateOfTest - time).Duration().Minutes < BE.Configuration.DURATION_OF_TEST)
                {
                    throw new Exception(string.Format("The tester {0} has no time on {1} at {2}", tester.ToString(), time.ToString("dddd, MMMM dd yyyy"), time.ToString("t")));
                }
            }

            dal.AddFutureTest(new Test(tester.Id, trainee.Id, time, address));
        }