예제 #1
0
        public bool SatisfiesRule(EmployeeShiftItem currentPlanningShift, IReadOnlyList <EmployeeShiftItem> pastScheduleItemList)
        {
            if (currentPlanningShift == null)
            {
                throw new ArgumentNullException("currentPlanningShift");
            }

            // if current employee has done two shifts or more, and there exists another employee
            // with less than two completed shifts, then we should give that employee a chance.
            // so we disqualify current employee from taking another shift until all employees have performed at least 2 shifts.

            var employeeCompletedShifts = pastScheduleItemList.Count(x => x.EmployeeId == currentPlanningShift.EmployeeId);

            if (employeeCompletedShifts >= 2)


            {
                var otherEmployeesCompletedShifts = pastScheduleItemList.GroupBy(x => x.EmployeeId);

                // if there exsits another employee with less than 2 completed shift
                if (otherEmployeesCompletedShifts.Any(x => x.Count() < 2))
                {
                    // current employee is not eligible to take another shift until others perform their required shifts
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(true);
            }
        }
 public bool IsEmployeeEligibleForShift(EmployeeShiftItem currentPlanningShift, IReadOnlyList<EmployeeShiftItem> pastScheduleItemList)
 {
     foreach (var rule in this.rules)
     {
         if (!rule.SatisfiesRule(currentPlanningShift, pastScheduleItemList))
         {
             return false;
         }
     }
     return true;
 }
        public void SatisfyNothingRuleTest()
        {
            var shiftRuleManager = new ShiftRuleManager();

            shiftRuleManager.SetRules(new List <IShiftRuleBase>()
            {
                new SatisfyNothingRule()
            });
            var testShift = new EmployeeShiftItem();

            var result = shiftRuleManager.IsEmployeeEligibleForShift(testShift, null);

            Assert.False(result);
        }
        public bool SatisfiesRule(EmployeeShiftItem currentPlanningShift, IReadOnlyList <EmployeeShiftItem> pastScheduleItemList)
        {
            if (currentPlanningShift == null)
            {
                throw new ArgumentNullException("currentPlanningShift");
            }

            // Weekends should be excluded from shift planning
            var dayInWeek = currentPlanningShift.Date.DayOfWeek;

            if (dayInWeek == DayOfWeek.Saturday || dayInWeek == DayOfWeek.Sunday)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #5
0
        public bool SatisfiesRule(EmployeeShiftItem currentPlanningShift, IReadOnlyList <EmployeeShiftItem> pastScheduleItemList)
        {
            if (currentPlanningShift == null)
            {
                throw new ArgumentNullException("currentPlanningShift");
            }

            var hasOtherShiftsToday = pastScheduleItemList.Any(x =>
                                                               x.EmployeeId == currentPlanningShift.EmployeeId && x.DayNumber == currentPlanningShift.DayNumber);

            if (hasOtherShiftsToday)
            {
                // this emplyee had another shift today and is not eligible for another working shift
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #6
0
        public bool SatisfiesRule(EmployeeShiftItem currentPlanningShift, IReadOnlyList <EmployeeShiftItem> pastScheduleItemList)
        {
            if (currentPlanningShift == null)
            {
                throw new ArgumentNullException("currentPlanningShift");
            }

            if (currentPlanningShift.ShiftNumber != 1 && currentPlanningShift.ShiftNumber != 2)
            {
                throw new ArgumentOutOfRangeException("currentPlanningShift.ShiftNumber");
            }

            if (currentPlanningShift.DayNumber == 0)
            {
                // employee is being considered for the first day of schedule
                return(true);
            }
            else if (currentPlanningShift.ShiftNumber == 1)
            {
                // this is not an afternoon shift
                return(true);
            }
            else // currentPlanningShift.ShiftNumber is 2
            {
                var hasAfternoonShiftsYesterday = pastScheduleItemList.Any(x =>
                                                                           x.EmployeeId == currentPlanningShift.EmployeeId && x.DayNumber == currentPlanningShift.DayNumber - 1 &&
                                                                           x.ShiftNumber == 2);

                if (hasAfternoonShiftsYesterday)
                {
                    // this emplyee had afternoon shift yesterday and is not eligible for another afternoon working shift today
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
예제 #7
0
        public bool SatisfiesRule(EmployeeShiftItem currentPlanningShift, IReadOnlyList <EmployeeShiftItem> pastScheduleItemList)
        {
            if (currentPlanningShift == null)
            {
                throw new ArgumentNullException("currentPlanningShift");
            }

            if (currentPlanningShift.ShiftNumber != 1 && currentPlanningShift.ShiftNumber != 2)
            {
                throw new ArgumentOutOfRangeException("currentPlanningShift.ShiftNumber");
            }

            if (currentPlanningShift.DayNumber < 2)
            {
                // employee is being considered for the first or second day of the schedule and is not eligible for exemption
                return(true);
            }
            else
            {
                var hasShiftsYesterday = pastScheduleItemList.Any(x =>
                                                                  x.EmployeeId == currentPlanningShift.EmployeeId && x.DayNumber == currentPlanningShift.DayNumber - 1);

                var hasShiftsTwoDaysAgo = pastScheduleItemList.Any(x =>
                                                                   x.EmployeeId == currentPlanningShift.EmployeeId && x.DayNumber == currentPlanningShift.DayNumber - 2);

                if (hasShiftsYesterday && hasShiftsTwoDaysAgo)
                {
                    // this emplyee had two consecutive day shifts and is eligible for exemption today (should no be selected today)
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
 public bool SatisfiesRule(EmployeeShiftItem currentPlanningShift, IReadOnlyList <EmployeeShiftItem> pastScheduleItemList)
 {
     return(false);
 }