Created
April 29, 2016 21:51
-
-
Save kdowswell/7db4facba7eb142df8272343bad2fece 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