public async Task CheckOffensesInRange(string userID, DateTime startDate, DateTime endDate) { List <WorkingDay> workingDays = await GetWorkingDaysInRange(userID, startDate, endDate); DailyJob offensesChecker = new DailyJob(db); foreach (WorkingDay workingDay in workingDays) { if (workingDay.IsAbsent()) { if (workingDay.Offenses?.Any() ?? false) { await offenseRepository.RemoveAll(workingDay.Offenses); } // Check if is on vacation if (!workingDay.User.GetCurrentVacationType(workingDay.Date).HasValue) { await offensesChecker.RecordDetectedOffense(workingDay.User, workingDay, OffenseDegree.Absence); } } else { await offensesChecker.CheckWorkingDayOffenses(workingDay); } } }
public async Task CheckAbsencesInRange(string userID, DateTime startDate, DateTime endDate) { List <WorkingDay> workingDays = await GetWorkingDaysInRange(userID, startDate, endDate); DailyJob offensesChecker = new DailyJob(db); foreach (WorkingDay workingDay in workingDays.Where(workingDay => workingDay.IsAbsent())) { if (workingDay.Offenses?.Any() ?? false) { await offenseRepository.RemoveAll(workingDay.Offenses); } await offensesChecker.RecordDetectedOffense(workingDay.User, workingDay, OffenseDegree.Absence); } }