Beispiel #1
0
        public static Week WeekSave(Week week)
        {
            if (!week.IsValid)
            {
                return(week);
            }

            Week result;

            if (week.IsNew)
            {
                result = WeekRepository.WeekInsert(week);
            }
            else
            {
                result = WeekRepository.WeekUpdate(week);
            }

            return(result);
        }
Beispiel #2
0
        public static void WeekAdd(DateTime startDate, DayOfWeek firstDayOfWeek, int numberOfPeriods, int year)
        {
            if (startDate.DayOfWeek != firstDayOfWeek)
            {
                throw new Csla.Rules.ValidationException("The start date's day of the week is not correct");
            }

            foreach (var week in WeekRepository.WeekFetchInfoList(year))
            {
                WeekRepository.WeekDelete(week.WeekId);
            }

            var numberOfWeeks = numberOfPeriods * 4;
            var endDate       = startDate.AddDays(numberOfWeeks * 7);
            var weekCounter   = 0;
            var periodCounter = 0;

            while (startDate < endDate)
            {
                var week = WeekRepository.WeekNew();

                week.StartDate = startDate;
                week.EndDate   = week.StartDate.AddDays(6);
                week.Year      = year;
                week.Period    = periodCounter + 1;

                WeekRepository.WeekSave(week);

                startDate = startDate.AddDays(7);

                weekCounter++;

                if (weekCounter % 4 == 0)
                {
                    periodCounter++;
                }
            }
        }
Beispiel #3
0
 public static bool WeekDelete(int weekId)
 {
     return(WeekRepository.WeekDelete(
                WeekRepository.WeekFetch(weekId)));
 }