private bool FixOrValidatePubTEK(PublishTekArgs args) { // If a 6 digit code has been send no LuhnModN validation is possible at this point. Just add the check code and return valid. if (args.GGDKey.Length == OldGGDKeyLength) { args.GGDKey = _lLuhnModNGenerator.CalculateCheckCode(args.GGDKey); return(true); } // Else the code should be 7 digits and validated. return(args.GGDKey.Length == ValidGGDKeyLength && _luhnModNValidator.Validate(args.GGDKey)); }
public string[] Validate(PublishTekArgs args) { if (args == null) { return(new[] { "Args is null." }); } var errors = new List <string>(); // The PubTEK key cannot be empty if (string.IsNullOrWhiteSpace(args.GGDKey)) { return(new[] { "PubTEK key is null or empty." }); } // The PubTEK key should be 6 or 7 characters in length if (args.GGDKey.Length != _luhnModNValidator.Config.ValueLength && args.GGDKey.Length != _luhnModNValidator.Config.ValueLength - 1) { return(new[] { "PubTEK key has incorrect length." }); } // The PubTEK key should only have character from the given set if (args.GGDKey.Any(x => !_luhnModNValidator.Config.CharacterSet.Contains(x))) { return(new[] { "PubTEK key contains invalid character." }); } // The PubTEK key should be validated for LuhnModN algorithm when it has 7 characters if (args.GGDKey.Length == _luhnModNValidator.Config.ValueLength && !_luhnModNValidator.Validate(args.GGDKey)) { return(new[] { "PubTEK key validation for LuhnModN failed." }); } //Should be a date only without time. args.SelectedDate = args.SelectedDate?.Date; if (!args.Symptomatic && (_dateTimeProvider.Snapshot.Date.AddDays(-30) > args.SelectedDate?.Date || args.SelectedDate?.Date > _dateTimeProvider.Snapshot.Date)) { errors.Add($"Selected date out of range - {args.SelectedDate}."); } return(errors.ToArray()); }