Example #1
0
        private void HousekeepSchedules()
        {
            _scheduleRepo = _scope.ServiceProvider.GetRequiredService <IAppRepository>();
            if (_scheduleRepo.GetScheduleCount() == 0)
            {
                NeedToGenerateNewSchedule = true;
                return;
            }

            var latestScheduleRecord = _scheduleRepo.GetLatestScheduleRecord();

            if (latestScheduleRecord < FirstWorkingDayDate)
            {
                var scheduleHistoryItems = new List <ScheduleHistory>();
                var existingSchedules    = _scheduleRepo.GetAllSchedules();
                foreach (var existingSchedule in existingSchedules)
                {
                    ScheduleHistory shItem = new ScheduleHistory();
                    shItem.PreviousId = existingSchedule.Id;
                    shItem.Shift      = existingSchedule.Shift;
                    shItem.StaffId    = existingSchedule.StaffId;
                    shItem.Date       = existingSchedule.Date;
                    scheduleHistoryItems.Add(shItem);
                }
                _scheduleRepo.AddToHistory(scheduleHistoryItems);
                _scheduleRepo.DeleteAllSchedules();
                NeedToGenerateNewSchedule = true;
            }
            else
            {
                NeedToGenerateNewSchedule = false;
            }
        }