private void _addAllResults(CalculatorResult result, List <RuleResult> allResults, bool getEmployeesOnly)
        {
            if (result.Results != null)
            {
                foreach (RuleResult ruleResult in result.Results)
                {
                    if (getEmployeesOnly)
                    {
                        if (ruleResult.CostCode == CostCodeEnum.EmployeeBaseCost || ruleResult.CostCode == CostCodeEnum.EmployeeFirstLetterADiscount)
                        {
                            allResults.Add(ruleResult);
                        }

                        continue;
                    }

                    allResults.Add(ruleResult);
                }
            }

            if (result.SubResults == null)
            {
                return;
            }

            foreach (CalculatorResult subResult in result.SubResults.Values)
            {
                _addAllResults(subResult, allResults, getEmployeesOnly);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="model">The model the calculation pertains to.</param>
        /// <returns></returns>
        public CalculatorResult Calculate(T model)
        {
            CalculatorResult result = new CalculatorResult();

            foreach (var rule in _rules)
            {
                rule.Calculate(model, result);
            }

            return(result);
        }
        public List <RuleResult> GetAllResults(CalculatorResult result, bool getEmployeesOnly = false)
        {
            List <RuleResult> allResults = new List <RuleResult>();

            if (result == null)
            {
                return(allResults);
            }

            _addAllResults(result, allResults, getEmployeesOnly);

            return(allResults);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="models">The models the calculation pertains to.</param>
        /// <param name="resultSet">An optional result set to add on to.</param>
        /// <returns>If a result set is passed in, it will return that result set with updated values.  Otherwise a new result set will be returned.</returns>
        public CalculatorResult Calculate(IEnumerable <T> models, CalculatorResult resultSet = null)
        {
            if (resultSet == null)
            {
                resultSet = new CalculatorResult();
            }

            foreach (var model in models)
            {
                CalculatorResult result = Calculate(model);

                resultSet.Total += result.Total;

                //add to sub result
                resultSet.SubResults[model.Id] = result;
            }

            return(resultSet);
        }
        public void Calculate(DependentModel model, CalculatorResult result)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result), "Result cannot be null.");
            }

            result.Results.Add(new RuleResult(CostCodeEnum.DependentBaseCost, _dependentCost));
            decimal costAfterDiscount = _dependentCost;

            //if the name starts with A, give them a discount
            if (model?.Name?.Length >= 1 && model.Name.ToLower()[0] == 'a')
            {
                decimal appliedDiscount = costAfterDiscount * _discount;
                result.Results.Add(new RuleResult(CostCodeEnum.DependentFirstLetterADiscount, appliedDiscount));
                costAfterDiscount -= appliedDiscount;
            }

            result.Total += costAfterDiscount;
        }
Beispiel #6
0
        public void Calculate(EmployeeModel employeeModel, CalculatorResult result)
        {
            _calculateEmployeeCost(employeeModel, result);

            _dependentCalculator.Calculate(employeeModel.Dependents, result);
        }