IEnumerable <ValidationResult> PseudoValidations(G10Context c) { string pseudoPattern = "^[\\W\\d_]+$"; bool isPseudoValid = Regex.IsMatch(Pseudo, pseudoPattern); if (!IsPseudoUnique(Pseudo, c)) { yield return(new ValidationResult("Pseudo already exists", new[] { nameof(Pseudo) })); } if (!isPseudoValid) { yield return(new ValidationResult("Invalid pseudo: letters/numbers/underscores allowed (Should begin by a letter)", new[] { nameof(Pseudo) })); } if (!IsPseudoLengthValid()) { yield return(new ValidationResult("Invalid pseudo (" + MinLengthPseudoPasswordName + " - " + MaxLengthPseudo + " char)", new[] { nameof(Pseudo) })); } if (!IsPasswordLengthValid()) { yield return(new ValidationResult("Invalid password (min " + MinLengthPseudoPasswordName + " char)", new[] { nameof(Password) })); } }
static bool IsPseudoUnique(string pseudo, G10Context c) { return((from u in c.Users where u.Pseudo == pseudo select u).FirstOrDefault() == null); }