Skip to content

Instantly share code, notes, and snippets.

public class ValidatorHandler<TRequest, TResponse>
: IRequestHandler<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
private readonly IRequestHandler<TRequest, TResponse> _inner;
private readonly IValidator<TRequest> _validator;
public ValidatorHandler(IRequestHandler<TRequest, TResponse> inner,
[ImportModelStateFromTempData]
public ActionResult Register()
{
return View();
}
[HttpPost, ValidateAntiForgeryToken, ValidateModelState]
public ActionResult Register(RegisterViewModel model)
{
var command = _mapper.Map<RegisterCommand>(model);
[ImportModelStateFromTempData]
public ActionResult Register()
{
return View();
}
[HttpPost, ValidateAntiForgeryToken, ValidateModelState]
public ActionResult Register(RegisterViewModel model)
{
var command = _mapper.Map<RegisterCommand>(model);
public class RegsiterCommandValidator : IValidator<RegisterCommand>
{
private readonly IValidationResult _validationResult;
private readonly IDbContext _context;
public RegsiterCommandValidator(IValidationResult validationResult, IDbContext context)
{
_validationResult = validationResult;
_context = context;
}
public class RegisterViewModel
{
[Required, Range(3, 50)]
public string FirstName { get; set; }
[Required, Range(3, 50)]
public string LastName { get; set; }
[Required, Range(3, 50)]
public string UserName { get; set; }
[Required, EmailAddress]
public string Email { get; set; }
[ImportModelStateFromTempData]
public ActionResult Register()
{
return View();
}
[HttpPost, ValidateAntiForgeryToken, ValidateModelState]
public ActionResult Register(RegisterViewModel model)
{
var command = _mapper.Map<RegisterCommand>(model);
public class RegsiterCommandValidator : MessageValidator<RegisterCommand>
{
private readonly IAfaemsDbContext _context;
public RegsiterCommandValidator(IAfaemsDbContext context)
{
_context = context;
}
public override ValidationResult Validate(RegisterCommand command)
public abstract class MessageValidator<IRequest>
{
private readonly DataAnnotationsValidator _dataAnnotationsValidator;
protected ValidationResult _result;
protected MessageValidator()
{
_dataAnnotationsValidator = new DataAnnotationsValidator();
_result = new ValidationResult();
}
public class RegisterViewModel
{
[Required, StringLength(50)]
public string FirstName { get; set; }
[Required, StringLength(50)]
public string LastName { get; set; }
[Required, StringLength(50)]
public string UserName { get; set; }
[Required, EmailAddress, StringLength(250)]
public string Email { get; set; }
public class RegsiterCommandValidator : MessageValidator<RegisterCommand>
{
private readonly IDbContext _context;
public RegsiterCommandValidator(IDbContext context)
{
_context = context;
}
public override ValidationResult Validate(RegisterCommand command)