Exemple #1
0
 public ValidationError(ValidationErrorResult validationResult)
     : base(validationResult.ErrorMessage)
 {
     this.ErrorCode    = validationResult.ErrorCode;
     this.ErrorMessage = validationResult.ErrorMessage;
     this.Violations   = validationResult.Errors;
 }
 public ValidationError(ValidationErrorResult validationResult)
     : base(validationResult.ErrorMessage)
 {
     this.errorCode = validationResult.ErrorCode;
     this.ErrorMessage = validationResult.ErrorMessage;
     this.Violations = validationResult.Errors;
 }
Exemple #3
0
 public static void ThrowIfNotValid(ValidationErrorResult validationResult)
 {
     if (!validationResult.IsValid)
     {
         throw new ValidationError(validationResult);
     }
 }
        /// <summary>
        /// Converts the validation result to an error result which will be serialized by ServiceStack in a clean and human-readable way.
        /// </summary>
        /// <param name="result">The validation result</param>
        /// <returns></returns>
        public static ValidationErrorResult ToErrorResult(this ValidationResult result)
        {
            var validationResult = new ValidationErrorResult();
            foreach (var error in result.Errors)
                validationResult.Errors.Add(new ValidationErrorField(error.ErrorCode, error.PropertyName, error.ErrorMessage, error.AttemptedValue));

            return validationResult;
        }
 /// <summary>
 /// Merge errors from another <see cref="ValidationErrorResult"/>
 /// </summary>
 /// <param name="result"></param>
 public void Merge(ValidationErrorResult result)
 {
     if (result != null)
     {
         foreach (var e in result.Errors)
         {
             Errors.Add(e);
         }
     }
 }
        public static object CreateErrorResponse(object request, ValidationErrorResult validationError)
        {
            var responseStatus = validationError.ToResponseStatus();

            var errorResponse = CreateErrorResponse(
                request,
                new ValidationError(validationError),
                responseStatus);

            return errorResponse;
        }
        /// <summary>
        /// Converts the validation result to an error result which will be serialized by ServiceStack in a clean and human-readable way.
        /// </summary>
        /// <param name="result">The validation result</param>
        /// <returns></returns>
        public static ValidationErrorResult ToErrorResult(this ValidationResult result)
        {
            var validationResult = new ValidationErrorResult();
            foreach (var error in result.Errors)
            {
                validationResult.Errors.Add(new ValidationErrorField(error.ErrorCode, error.PropertyName, error.ErrorMessage, error.AttemptedValue) {
                    Meta = error.CustomState as Dictionary<string, string> ?? error.PlaceholderValues
                });
            }

            return validationResult;
        }
 public static void ThrowIfNotValid(ValidationErrorResult validationResult)
 {
     if (!validationResult.IsValid)
     {
         throw new ValidationError(validationResult);
     }
 }
        /// <summary>
        /// Merge errors from another <see cref="ValidationErrorResult"/>
        /// </summary>
        /// <param name="result"></param>
        public void Merge(ValidationErrorResult result)
        {
            if (result == null) return;

            foreach (var e in result.Errors)
            {
                Errors.Add(e);
            }
        }