Exemple #1
0
        public IEnumerable <Schedule> GenerateSchedule(int weeks = 4)
        {
            var lastScheduledWeek = scheduleRepository.GetLastScheduledWeek().ToList();

            var lastScheduledDate = lastScheduledWeek.LastOrDefault()?.Date;

            var engineerIds = engineerRepository.GetAllActive().Select(x => x.Id).ToList();

            var engineerRotation = new List <Schedule>();

            for (var i = 0; i < weeks; i++)
            {
                var startingDate = DateHelpers.NextWeekday(lastScheduledDate);

                var shifts = ScheduleHelper.AssignShift(engineerIds, lastScheduledWeek);

                (lastScheduledWeek, lastScheduledDate) = ScheduleHelper.ScheduleWeekRotation(startingDate, shifts);

                engineerRotation.AddRange(lastScheduledWeek);
            }

            scheduleRepository.Save(engineerRotation);

            return(engineerRotation);
        }