private static string PrintOnlyNumber(AccountNumber accountNumber) { var numberPart = ""; var digits = accountNumber.Digits; if (digits.Any()) numberPart = string.Join("", digits.Select(PrintSingleDigit()).ToArray()); return numberPart; }
public static string PrintNumberRepresentation(AccountNumber accountNumber) { if (accountNumber == null) return ""; var number = PrintOnlyNumber(accountNumber); var suffix = PrintSuffixPart(accountNumber, number); var result = string.Format("{0} {1}", number, suffix).TrimEnd(); return result; }
public static int CalculateChecksum(AccountNumber accountNumber) { var factor = 1; var checksum = 0; foreach (var digit in accountNumber.Digits.Reverse()) { checksum += factor * digit.Value; factor++; } return checksum; }
private static string PrintSuffixPart(AccountNumber accountNumber, string result) { if (result.Contains(IllegalDigitMark)) return IllegalSuffix; else { var checksum = ChecksumCalculator.CalculateChecksum(accountNumber); var checksumValid = ChecksumValidator.IsChecksumValid(checksum); if (!checksumValid) return ErrorSuffix; } return ""; }