/// <summary> /// Calculates the roll up value based on the rollup method set /// </summary> /// <param name="rollupInfo">Rollup information</param> /// <returns>Calculated rollup value</returns> private decimal?CalculateRollupTargetValue(RollupInfo rollupInfo) { decimal?rolledupValue = null; // Retrieve all child targets var childTargetIds = targetRepository.GetAll().Where(x => x.ParentTargetId == rollupInfo.ParentTargetId && x.IsActive).Select(y => y.Id).ToList(); switch (rollupInfo.RollupMethodId) { // "Sum of Children" case Constants.RollupMethodSumOfChildren: { IRollupStrategy sumOfChildrenRollup = CreateSumOfChildrenRollupStrategy(); rolledupValue = sumOfChildrenRollup.CalculateRollupTarget(rollupInfo, childTargetIds); break; } // "Average of Children" case Constants.RollupMethodAverageOfChildren: { IRollupStrategy avgOfChildrentRollup = CreateAverageOfChildrenRollupStrategy(); rolledupValue = avgOfChildrentRollup.CalculateRollupTarget(rollupInfo, childTargetIds); break; } // "Same as Child" case Constants.RollupMethodSameAsChild: { IRollupStrategy sameAsChildRollup = CreateSameAsChildRollupStrategy(); rolledupValue = sameAsChildRollup.CalculateRollupTarget(rollupInfo, childTargetIds); break; } } // Round the rolled up value to two decimal places if (rolledupValue.HasValue) { var rollupValue = decimal.Round(rolledupValue.Value, 2, MidpointRounding.AwayFromZero); if (rollupInfo.DataTypeId == Constants.DataTypeWholeNumber) { rollupValue = decimal.Round(rolledupValue.Value, 0, MidpointRounding.AwayFromZero); } return(rollupValue); } return(rolledupValue); }