public SAIDGeneratorResponse ValidateSAIDNumber(string IDNumber) { SAIDGeneratorResponse ValidationResponse = new SAIDGeneratorResponse(); ValidationResponse.Success = false; if (IDNumber == null || IDNumber.Trim() == "") //Ensures an empty value was not received. { ValidationResponse.Message = "Invalid - Empty values are not allowed."; } else { IDNumber = IDNumber.Trim(); if (!SAIDNumberWorker.SAIDNumberRegex.IsMatch(IDNumber)) //Ensures a 13 digit numerical value was received. { ValidationResponse.Message = "Invalid - Enter a 13 digit numerical only ID number."; } else //Validation passed. { if (this.ValidateIDControlDigit(IDNumber) != int.Parse(IDNumber[IDNumber.Length - 1].ToString())) //Checks if the last digit of the ID number matches the control digit. { ValidationResponse.Message = "Invalid - The ID Number entered is not valid."; } else { ValidationResponse.Success = true; ValidationResponse.Message = "Validated - The ID Number entered is correct."; } } } return ValidationResponse; }
public SAIDGeneratorResponse GenerateRandomSAIDNumber() { SAIDGeneratorResponse GenerationResponse = new SAIDGeneratorResponse(); int MaxRetries = 15; //Max allowed retries, allow retry, but prevent an infinite loop. string IDString = this.ConcatenateRandomIDParts(); GenerationResponse = this.ValidateSAIDNumber(IDString); while (!GenerationResponse.Success && MaxRetries < 15) { IDString = this.ConcatenateRandomIDParts(); GenerationResponse = this.ValidateSAIDNumber(IDString); MaxRetries += 1; } if (!GenerationResponse.Success) //Random SA ID Number generation failed. { GenerationResponse.Message = "Error - An unforseen error prevented a random SA ID number from being generated. Please try again."; } else { GenerationResponse.Message = IDString; } return GenerationResponse; }