示例#1
0
        public bool IsTimeSlogValidForBoard(TimeSlot timeSlot)
        {
            if (timeSlot == null)
            {
                throw new ArgumentNullException(nameof(timeSlot));
            }

            if (!timeSlot.ScheduledFor.HasValue)
            {
                throw new ArgumentNullException(nameof(timeSlot.ScheduledFor));
            }

            if (StartsAt > timeSlot.ScheduledFor)
            {
                return(false);
            }

            if (EndsAt < timeSlot.ScheduledToConcludeAt)
            {
                return(false);
            }

            return(SchedulerTimeSlot.All(m =>
            {
                var candidateStart = timeSlot.ScheduledFor;
                var candidateEnd = timeSlot.MandatoryBreakConcludesAt;
                var existingRecordStart = m.ScheduledFor;
                var existingRecordEnd = m.MandatoryBreakConcludesAt;

                if (candidateStart >= existingRecordStart && candidateStart < existingRecordEnd)
                {
                    return false;
                }

                if (candidateEnd >= existingRecordStart && candidateEnd < existingRecordEnd)
                {
                    return false;
                }

                return true;
            }));
        }
示例#2
0
        public DateTime?GetTimeForTimeSlot(TimeSlot timeSlot)
        {
            var timeSlotCandidate = TimeSlotFactory.CreateTimeSlot(timeSlot.TimeSlotType);

            timeSlotCandidate.SetTime(StartsAt < DateTime.Now ? DateTime.Now : StartsAt);
            if (IsTimeSlogValidForBoard(timeSlotCandidate))
            {
                return(timeSlotCandidate.ScheduledFor);
            }

            foreach (var alreadyScheduledTimeSlots in SchedulerTimeSlot.Where(m => m.MandatoryBreakConcludesAt.HasValue))
            {
                timeSlotCandidate.SetTime(alreadyScheduledTimeSlots.MandatoryBreakConcludesAt.GetValueOrDefault());
                if (IsTimeSlogValidForBoard(timeSlotCandidate))
                {
                    return(timeSlotCandidate.ScheduledFor);
                }
            }
            return(null);
        }
示例#3
0
 public bool AddTimeSlot(TimeSlot timeSlot)
 {
     if (timeSlot.ScheduledFor.HasValue)
     {
         if (!IsTimeSlogValidForBoard(timeSlot))
         {
             return(false);
         }
     }
     else
     {
         var scheduledFor = GetTimeForTimeSlot(timeSlot);
         if (!scheduledFor.HasValue)
         {
             return(false);
         }
         timeSlot.SetTime(scheduledFor.Value);
     }
     SchedulerTimeSlot.Add(timeSlot);
     return(true);
 }