Created
April 30, 2016 16:59
-
-
Save kdowswell/421345752f510e57a263be2ed1533373 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 : MessageValidator<RegisterCommand> | |
{ | |
private readonly IDbContext _context; | |
public RegsiterCommandValidator(IDbContext context) | |
{ | |
_context = context; | |
} | |
public override ValidationResult Validate(RegisterCommand command) | |
{ | |
ValidateAnnotations(command); | |
if (_context.Users.Any(x => x.UserName == command.UserName)) | |
_result.AddError(new ValidationFailure("UserName", "The username is invalid.")); | |
if (IsFiveOclock()) | |
_result.AddError(new ValidationFailure("", "Go to happy hour!")); | |
return _result; | |
} | |
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