-
-
Save NDiiong/46e0cd19ee0a0793a79e2b38d3bf25a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RegsiterCommandValidator : IValidator<RegisterCommand> | |
{ | |
private readonly IValidationResult _validationResult; | |
private readonly IDbContext _context; | |
public RegsiterCommandValidator(IValidationResult validationResult, IDbContext context) | |
{ | |
_validationResult = validationResult; | |
_context = context; | |
} | |
public IValidationResult Validate(RegisterCommand command) | |
{ | |
if (_context.Users.Any(x => x.UserName == command.UserName)) | |
_validationResult.AddError(new ValidationFailure("UserName", "The username is invalid.")); | |
if (IsFiveOclock()) | |
_validationResult.AddError(new ValidationFailure("", "Go to happy hour!")); | |
return _validationResult; | |
} | |
private bool IsFiveOclock() | |
{ | |
//it is somewhere! | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment