public bool IsWorkingDay(DateTime testDate)
 {
     if (testDate.DayOfWeek == DayOfWeek.Saturday || testDate.DayOfWeek == DayOfWeek.Sunday)
     {
         return(false);
     }
     if (_cacheService.Holidays.Any(h => NonWorkingHolidays.Contains(h.DateType) && h.Date == testDate.Date))
     {
         return(false);
     }
     return(true);
 }
        public int GetWorkDaysBetween(DateTime firstDate, DateTime secondDate)
        {
            if (secondDate < firstDate)
            {
                throw new ArgumentException("First Date must be before secondDate");
            }

            if (firstDate.TimeOfDay.Ticks != 0)
            {
                throw new ArgumentException($"{nameof(firstDate)} includes a time other than midnight. Use the Date property to get a pure date.", nameof(firstDate));
            }

            if (secondDate.TimeOfDay.Ticks != 0)
            {
                throw new ArgumentException($"{nameof(secondDate)} includes a time other than midnight. Use the Date property to get a pure date.", nameof(secondDate));
            }

            if (firstDate.Kind != secondDate.Kind)
            {
                throw new ArgumentException($"{nameof(firstDate)} has kind {firstDate.Kind} which is different from {nameof(secondDate)} kind {secondDate.Kind}");
            }

            int fullWeeks = (secondDate - firstDate).Days / 7;

            int rest = (secondDate - firstDate).Days % 7;

            if (secondDate.DayOfWeek < firstDate.DayOfWeek) // Wraps over a weekend.
            {
                rest -= secondDate.DayOfWeek == DayOfWeek.Sunday ? 1 : 2;
            }
            else
            {
                rest -= firstDate.DayOfWeek == DayOfWeek.Sunday ? 1 : 0;
            }

            rest -= _cacheService.Holidays.Where(h =>
                                                 NonWorkingHolidays.Contains(h.DateType) &&
                                                 h.Date >= firstDate && h.Date < secondDate)
                    .AsEnumerable()
                    .Where(h => h.Date.DayOfWeek >= DayOfWeek.Monday && h.Date.DayOfWeek <= DayOfWeek.Friday)
                    .Count();

            return(fullWeeks * 5 + rest);
        }