public List <string> GetPostCodeLines(string path) { var postalCodeLines = new List <string>(); var files = _directory.GetFiles(path); foreach (var file in files) { var lines = _fileIo.ReadAllLines(file).ToList(); foreach (var line in lines) { var words = line.Split(' '); for (var i = 0; i < words.Length; i++) { var postCodeDigit = new string(words[i].Where(char.IsDigit).ToArray()); if (postCodeDigit.Length == 4 && i != words.Length) { var postCodeAlphabets = new string(words[i + 1].Where(char.IsLetter).ToArray()); if (postCodeAlphabets.Length == 2) { var postalCode = $"{postCodeDigit}{postCodeAlphabets}"; // Validate Postal code var isValidPostalCode = _postCodeValidationService.Validate(postalCode); if (isValidPostalCode) { postalCodeLines.Add(line); break; } } } } } } return(postalCodeLines); }
public IEnumerable <IFraudResult> Check() { var orders = _fileIo.ReadAllLines(_settings.FilePath) .Select(line => line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) .Select(items => new Order { OrderId = int.Parse(items[0]), DealId = int.Parse(items[1]), Email = items[2].ToLower(), Street = items[3].ToLower(), City = items[4].ToLower(), State = items[5].ToLower(), ZipCode = items[6], CreditCard = items[7] }); // NORMALIZE var normalizedOrder = _orderNormalizationService.NormalizeOrder(orders).ToList(); // CHECK FRAUD var fraudResults = _checkFraudService.CheckFraud(normalizedOrder); return(fraudResults); }