/* * Built in object validator */ public override bool Validate(out ImmutableArray <string> errors, CRUDOperation operation = CRUDOperation.Create) { IValitResult result = ValitRules <User> .Create() .Ensure(m => m.AuthKey, _ => _ .Required() .WithMessage(FormatValidationError(Errors.FIELD_REQUIRED, "authKey")) .MaxLength(50) .WithMessage(FormatValidationError(Errors.FIELD_MAXLENGTH, "authKey", "50")) .Matches(@"^[a-zA-Z][\w]*$") .WithMessage(FormatValidationError(Errors.FIELD_REGEX_MATCH, "authKey", @"^[a-zA-Z][\w]*$"))) .Ensure(m => m.RawPassword, _ => _ .Required() .WithMessage(FormatValidationError(Errors.FIELD_REQUIRED, "password")) .When(m => operation.Equals(CRUDOperation.Create) || operation.Equals(CRUDOperation.Update) && !m.RawPassword.IsNullOrEmpty()) .MinLength(5) .WithMessage(FormatValidationError(Errors.FIELD_MINLENGTH, "password", "5")) .When(m => operation.Equals(CRUDOperation.Create) || operation.Equals(CRUDOperation.Update) && !m.RawPassword.IsNullOrEmpty()) .MaxLength(72) .WithMessage(FormatValidationError(Errors.FIELD_MAXLENGTH, "password", "72")) .When(m => operation.Equals(CRUDOperation.Create) || operation.Equals(CRUDOperation.Update) && !m.RawPassword.IsNullOrEmpty())) .Ensure(m => m.FullName, _ => _ .MaxLength(50) .WithMessage(FormatValidationError(Errors.FIELD_MAXLENGTH, "fullName", "50")) .When(m => !m.FullName.IsNullOrEmpty())) .Ensure(m => m.EmailAddress, _ => _ .Required() .WithMessage(FormatValidationError(Errors.FIELD_REQUIRED, "email")) .Email() .WithMessage(FormatValidationError(Errors.FIELD_EMAIL, "email"))) .Ensure(m => m.EncryptCertificate, _ => _ .Required() .WithMessage(FormatValidationError(Errors.FIELD_REQUIRED, "encryptCertificate")) .When(m => operation.Equals(CRUDOperation.Create))) .For(this) .Validate(); errors = result.ErrorMessages; return(result.Succeeded); }