protected override bool Validate() { var result = ValitRules <User> .Create() .Ensure(u => u.Email, _ => _ .Required() .WithMessage(WeatherAttackNotifications.User.EmailIsRequired) .Satisfies(u => u.Trim().Length > Rules.User.Email.MinLength) .WithMessage(WeatherAttackNotifications.User.InvalidEmail) .Email() .WithMessage(WeatherAttackNotifications.User.InvalidEmail) .MaxLength(Rules.User.Email.MaxLength) .WithMessage(WeatherAttackNotifications.User.InvalidEmail)) .Ensure(u => u.Username, _ => _ .Required() .WithMessage(WeatherAttackNotifications.User.UsernameIsRequired) .Satisfies(u => u.Trim().Length > Rules.User.Username.MinLength) .WithMessage(WeatherAttackNotifications.User.InvalidUsername) .MaxLength(Rules.User.Username.MaxLength) .WithMessage(WeatherAttackNotifications.User.InvalidUsername)) .Ensure(u => u.Password, _ => _ .Required() .WithMessage(WeatherAttackNotifications.User.PasswordIsRequired)) .For(this) .Validate(); AddNotification(WeatherAttackNotifications.Get(result.ErrorMessages)); return(!HasNotification()); }
protected override bool Validate() { var result = ValitRules <AddUserCommand> .Create() .Ensure(c => c.User, _ => _ .Required() .WithMessage(WeatherAttackNotifications.Command.UserIsRequired)) .For(this) .Validate(); AddNotification(WeatherAttackNotifications.Get(result.ErrorMessages)); return(Notifications.Count == 0); }