Ejemplo n.º 1
0
        public static IEnumerable <EmployeeBonus> Generate(IEnumerable <Employee> employees,
                                                           IEnumerable <Contract> contracts,
                                                           DateTime startDate,
                                                           DateTime finalDate)
        {
            if (startDate > finalDate)
            {
                throw new ArgumentException($"'{nameof(finalDate)}' ({finalDate:dd.MM.yyyy}) cannot be less than " +
                                            $"'{nameof(startDate)}' ({startDate:dd.MM.yyyy}).");
            }

            employees = FilterEmployeesByDate(employees, startDate, finalDate);
            contracts = FilterContractsByDate(contracts, startDate, finalDate);

            var calculators = new BonusCalculators(contracts, startDate, finalDate);

            return(CalculateEmployeeBonuses(employees, calculators));
        }
Ejemplo n.º 2
0
 private static IEnumerable <EmployeeBonus> CalculateEmployeeBonuses(IEnumerable <Employee> employees,
                                                                     BonusCalculators calculators) =>
 from employee in employees
 let bonus = employee.BonusCodes
             .Sum(bonusCode => calculators.BonusCalculatorByBonusCode[bonusCode - 1](employee))
             select new EmployeeBonus(employee.Id, bonus);