public string GenerateNumber() { Random random = GenerateRandom(); var response = new CardResponseObject(); // Since no formatType was passed in, randomly choose one from the available choices _specificFormatType = _formatTypes.OrderBy(item => random.Next()).First(); _specificFormatType.ExplodeIINRange(); // Since no formatTypelength was passed in, randomly choose one from the available choices int formatTypelength = _specificFormatType.LengthOfDigits[random.Next(_specificFormatType.LengthOfDigits.Length)]; _lengthOfDigits = _specificFormatType.LengthOfDigits[Array.IndexOf(_specificFormatType.LengthOfDigits, formatTypelength)]; _IIN = _specificFormatType.IINRange[GenerateRandom().Next(_specificFormatType.IINRange.Count)]; response.CardNumber = GenerateLunhNumber(); response.CardIssuer = _specificFormatType.Issuer; response.CardLength = _lengthOfDigits; response.CardIID = _IIN; response.CardDisplayFormat = _specificFormatType.DisplayFormat.FirstOrDefault(x => x.FormatLength.Equals(_lengthOfDigits)).DigitSpacingFormat; response.Success = true; return(Newtonsoft.Json.JsonConvert.SerializeObject(response)); }
public string GenerateNumber(string formatType) { _logger.LogInformation("Beginning of GenerateNumber(string)"); Random random = GenerateRandom(); var response = new CardResponseObject(); _specificFormatType = _formatTypes.SingleOrDefault(x => x.abbr.Equals(formatType, StringComparison.CurrentCultureIgnoreCase)); if (_specificFormatType == null) { var error = $"An appropriate formatType was not specified"; _logger.LogError(error); response.CardNumber = error; return(Newtonsoft.Json.JsonConvert.SerializeObject(response)); } _specificFormatType.ExplodeIINRange(); // Since no formatTypelength was passed in, randomly choose one from the available choices int formatTypelength = _specificFormatType.LengthOfDigits[random.Next(_specificFormatType.LengthOfDigits.Length)]; _lengthOfDigits = _specificFormatType.LengthOfDigits[Array.IndexOf(_specificFormatType.LengthOfDigits, formatTypelength)]; _IIN = _specificFormatType.IINRange[GenerateRandom().Next(_specificFormatType.IINRange.Count)]; response.CardNumber = GenerateLunhNumber(); response.CardIssuer = _specificFormatType.Issuer; response.CardLength = _lengthOfDigits; response.CardIID = _IIN; response.CardDisplayFormat = _specificFormatType.DisplayFormat.FirstOrDefault(x => x.FormatLength.Equals(_lengthOfDigits)).DigitSpacingFormat; response.Success = true; return(Newtonsoft.Json.JsonConvert.SerializeObject(response)); }
public string GenerateNumber(string formatType, int formatTypelength, int formatStart) { _logger.LogInformation("Beginning of GenerateNumber(string, int, int)"); var response = new CardResponseObject(); _specificFormatType = _formatTypes.SingleOrDefault(x => x.abbr.Equals(formatType, StringComparison.CurrentCultureIgnoreCase)); if (_specificFormatType == null) { var error = $"An appropriate formatType was not specified"; _logger.LogError(error); response.CardNumber = error; return(Newtonsoft.Json.JsonConvert.SerializeObject(response)); } else if (Array.IndexOf(_specificFormatType.LengthOfDigits, formatTypelength) == -1) { var error = $"An inappropriate length for {_specificFormatType.Issuer} was not specified"; _logger.LogError(error); response.CardNumber = error; return(Newtonsoft.Json.JsonConvert.SerializeObject(response)); } _specificFormatType.ExplodeIINRange(); if (_specificFormatType.IINRange.IndexOf(formatStart) == -1) { var error = $"An inappropriate start value for {_specificFormatType.Issuer} was not specified"; _logger.LogError(error); response.CardNumber = error; return(Newtonsoft.Json.JsonConvert.SerializeObject(response)); } _lengthOfDigits = _specificFormatType.LengthOfDigits[Array.IndexOf(_specificFormatType.LengthOfDigits, formatTypelength)]; _IIN = formatStart; response.CardNumber = GenerateLunhNumber(); response.CardIssuer = _specificFormatType.Issuer; response.CardLength = _lengthOfDigits; response.CardIID = _IIN; response.CardDisplayFormat = _specificFormatType.DisplayFormat.FirstOrDefault(x => x.FormatLength.Equals(_lengthOfDigits)).DigitSpacingFormat; response.Success = true; return(Newtonsoft.Json.JsonConvert.SerializeObject(response)); }