Пример #1
0
        public void UpdateRange(IEnumerable <PeriodDate> periodDates)
        {
            ValidatePeriodDates(periodDates);

            var term = TermService.Get(GetTermIdFromPeriodDates(periodDates));

            term.PeriodDates = periodDates.ToList();

            TermService.Update(term);
        }
Пример #2
0
        private void ValidatePeriodDates(IEnumerable <PeriodDate> periodDates)
        {
            if (periodDates.Count() < totalNumberOfPeriods)
            {
                throw new ArgumentNullException("periodDates");
            }

            var term = TermService.Get(GetTermIdFromPeriodDates(periodDates));

            var outsideTermRange = periodDates
                                   .Count(pd => pd.StartDate <term.StartDate || pd.EndDate> term.EndDate);

            if (outsideTermRange > 0)
            {
                throw new ArgumentException("A period date is not between the term star and end dates.");
            }

            if (periodDates.Count(pd => pd.StartDate > pd.EndDate) > 0)
            {
                throw new ArgumentException("A period start date is greater its end date.");
            }

            if (periodDates.Count(pd => pd.StartDate.Equals(pd.EndDate)) > 0)
            {
                throw new ArgumentException("A period start date is equals to its end date.");
            }

            var periodIds = periodDates.Select(p => p.PeriodId).ToList();

            for (int i = totalNumberOfPeriods; i > 0; i--)
            {
                var periodDate = periodDates.SingleOrDefault(pd => pd.PeriodId == i);

                var overlaps = periodDates
                               .Where(pd => pd.EndDate >= periodDate.StartDate && pd.PeriodId != periodDate.PeriodId && periodIds.Contains(pd.PeriodId));

                if (overlaps.Count() > 0)
                {
                    throw new ArgumentException("A period dates' range ovelaps with another period dates' range.");
                }

                periodIds.Remove(i);
            }
        }
Пример #3
0
 private void SetOfferingProperties(Offering offering)
 {
     offering.Course    = CourseService.Get(offering.CourseId);
     offering.Professor = ProfessorService.Get(offering.ProfessorId);
     offering.Term      = TermService.Get(offering.TermId);
 }