Skip to content

Instantly share code, notes, and snippets.

@kdowswell
Created April 30, 2016 16:59
Show Gist options
  • Save kdowswell/421345752f510e57a263be2ed1533373 to your computer and use it in GitHub Desktop.
Save kdowswell/421345752f510e57a263be2ed1533373 to your computer and use it in GitHub Desktop.
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