0
djfuzzy created
I have a DTO that includes validation including some custom validation, but it is not being caught and thrown. I thought these should be thrown automatically. Here is my DTO:
public class CreateUserInput : ICustomValidate
{
[Required]
[StringLength(User.MaxNicknameLength, MinimumLength = User.MinNicknameLength)]
public string Nickname { get; set; }
[Required]
[EmailAddress]
[StringLength(AbpUserBase.MaxEmailAddressLength)]
public string EmailAddress { get; set; }
[Required]
[DisableAuditing]
public string PasswordHashed { get; set; }
public bool IsActive { get; set; }
public void AddValidationErrors(List<ValidationResult> results)
{
if (Regex.IsMatch(Nickname, User.NicknameFormatValidationRegex))
{
throw new UserFriendlyException(string.Format("Nickname must be between {0} and {1} characters, may " +
"only contain letters, numbers, spaces, hyphens, underscores and periods, and cannot begin or end " +
"with spaces.", User.MinNicknameLength, User.MaxNicknameLength));
}
}
}
1 Answer(s)
-
0
Hi,
Actually, you don't need to throw exception. Just add a new item to results list. But, this should also work. If you are sure, please create an issue on Github: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/new">https://github.com/aspnetboilerplate/as ... issues/new</a>