Example #1
0
        private async Task CheckIfWeAreRespectingRestDays(Engineer engineer, DateTime date, Team team)
        {
            var lastShiftBeforeDate = engineer.Shifts
                                      .Where(s => s.Date <= date)
                                      .OrderByDescending(s => s.Date)
                                      .FirstOrDefault();

            if (lastShiftBeforeDate == null)
            {
                return;
            }

            int restDays = (date - lastShiftBeforeDate.Date).Days;

            if (restDays > team.MinimumRestDaysAfterSupporting)
            {
                return;
            }

            // This may happen in real life, so instead of throwing an exception (because it's not),
            // we just notify someone (INotifierService is responsible for knowing who and how to notify)...
            await notifierService.MinimumRestDaysNotBeingRespected(engineer, lastShiftBeforeDate.Date, date).ConfigureAwait(false);
        }