Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NDiiong/46e0cd19ee0a0793a79e2b38d3bf25a1 to your computer and use it in GitHub Desktop.
Save NDiiong/46e0cd19ee0a0793a79e2b38d3bf25a1 to your computer and use it in GitHub Desktop.
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