public decimal GetFactorValue(Guid factorId, DateTime calculationDate) { var factorValue = Context.FactorValue(calculationDate, factorId); if (factorValue == null) { var message = string.Format(Resources.FactorValueNotFound, factorId, calculationDate); throw new NullReferenceException(message); } return(factorValue.Value); }
public CalculationResult CalculateEmission(DateTime effectiveDate, decimal distance, ServiceType serviceType, decimal chargeMass, bool reversal) { var distanceType = GetDistanceType(distance, serviceType); var factorId = FactorMapping[distanceType]; var factorValue = context.FactorValue(effectiveDate, factorId); if (factorValue == null) { var message = string.Format(Resources.FactorValueNotFound, factorId, effectiveDate); throw new NullReferenceException(message); } var emissions = distance * (chargeMass / 1000) * factorValue; if (reversal) { emissions = emissions * -1; } var calculationDate = context.CalculationDateForFactorId(factorId); return(new CalculationResult { CalculationDate = calculationDate, ActivityGroupId = ActivityMapping[distanceType], Emissions = emissions }); }