/// <summary>
        /// Copies the validation errors.
        /// </summary>
        /// <param name="modelState">State of the model.</param>
        /// <param name="validationErrors">The validation errors.</param>
        public static void CopyValidationErrors(this ModelStateDictionary modelState, IList<ValidationError> validationErrors)
        {
            validationErrors.ForEach(error => modelState.AddModelError(error.Property, /* strValue, */ error.Message));

            //string strValue = null;
                //if (error.AttemptedValue != null)
                //    strValue = error.AttemptedValue.ToString();
        }
 public static ModelStateDictionary ThenAddRange(this ModelStateDictionary modelState, IEnumerable<ValidationResult> validationResults)
 {
     foreach (var error in validationResults)
     {
         if (error.MemberNames.Any())
             modelState.AddModelError(error.MemberNames.First(), error.ErrorMessage);
         else
             modelState.AddModelError(string.Empty, error.ErrorMessage);
     }
     return modelState;
 }
 public static ModelStateDictionary MergeWithValidatableObject(this ModelStateDictionary modelState, IValidatableObject obj)
 {
     IEnumerable<ValidationResult> errors = obj.Validate(new ValidationContext(obj, null, null));
     foreach (ValidationResult error in errors)
         foreach (string memberName in error.MemberNames)
         {
             if (modelState.ContainsKey(memberName))
                 modelState.AddModelError(memberName, error.ErrorMessage);
             else
                 modelState.AddModelError(memberName, error.ErrorMessage);
         }
     return modelState;
 }
 /// <summary>
 /// Add to the model state a list of error that came from properties. If the property name
 /// is empty, this one will be without property (general)
 /// </summary>
 /// <param name="modelState">State of the model.</param>
 /// <param name="propertyErrors">The property errors.</param>
 public static void AddValidationErrors(this ModelStateDictionary modelState, Exception exception)
 {
     if (exception is IValidationErrors)
     {
         foreach (var databaseValidationError in (exception as ValidationErrors).Errors)
         {
             modelState.AddModelError(databaseValidationError.PropertyName ?? string.Empty, databaseValidationError.PropertyExceptionMessage);
         }
     }
     else
     {
         modelState.AddModelError(string.Empty, exception.Message + (exception.Message != exception.GetBaseException().Message ? "\r\n" + exception.GetBaseException().Message : ""));
     }
 }
 /// <summary>
 /// Adds the list of errors to the Model State Dictionary.
 /// </summary>
 /// <param name="errors"></param>
 public static void AddModelErrors(this System.Web.Mvc.ModelStateDictionary state, IList<Models.ValidationResult> errors)
 {
     foreach (var item in errors)
     {
         state.AddModelError(item.Name, item.Message);
     }
 }
 public static void AddModelErrors(this ModelStateDictionary state, IEnumerable<ValidationError> errors)
 {
     foreach (var error in errors)
     {
         state.AddModelError(error.PropertyName, error.ErrorMessage);
     }
 }
 /// <summary>
 /// Add errors from entity to the model state.
 /// </summary>
 /// <param name="modelState"></param>
 /// <param name="entity"></param>
 public static void AddErrors(this ModelStateDictionary modelState, IErrors errors)
 {
     if (errors.Count > 0)
     {
         errors.EachFull(err => modelState.AddModelError("", err));
     }
 }
 public static void FillDataViolation(this ModelStateDictionary modelState, IEnumerable<DataViolationItem> violations)
 {
     foreach (var issue in violations)
     {
         modelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
     }
 }
 public static void AddErrorsFromIdentiyResult(this ModelStateDictionary modelState, IEnumerable<string> resultErrors)
 {
     foreach (string error in resultErrors)
     {
         modelState.AddModelError("", error);
     }
 }
Example #10
0
 /// <summary>
 /// Processes the specified model state.
 /// </summary>
 /// <param name="modelState">State of the model.</param>
 /// <param name="result">The result.</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
 public static bool Process(this ModelStateDictionary modelState, IValidationContainer result)
 {
     foreach (var r in result.ValidationErrors)
         foreach (var e in r.Value)
             modelState.AddModelError(r.Key, e);
     return modelState.IsValid;
 }
 public static void AgregarErrores(this ModelStateDictionary estado, Resultado resultado)
 {
     foreach (var error in resultado.Errores)
     {
         estado.AddModelError(error.Key, error.Value);
     }
 }
 public static void ApplyValidationFailures(this ModelStateDictionary state, IList<ValidationFailure> validationFailures)
 {
     foreach(var failure in validationFailures)
     {
         state.AddModelError(failure.PropertyName, failure.ErrorMessage);
     }
 }
 public static void AddRuleViolations(this ModelStateDictionary modelState, IEnumerable<RuleViolation> ruleViolations)
 {
     foreach (RuleViolation ruleViolation in ruleViolations)
     {
         modelState.AddModelError(ruleViolation.PropertyName ?? Guid.NewGuid().ToString(), ruleViolation.ErrorMessage);
     }
 }
        public static ModelStateDictionary AddModelErrors(this ModelStateDictionary modelState, CommandResult result)
        {
            foreach (var error in result.Errors)
                modelState.AddModelError(error.Key, error.Error);

            return modelState;
        }
Example #15
0
 public static void AddRuleErrors(this ModelStateDictionary modelState, RulesException ex)
 {
     foreach (var x in ex.Errors)
     {
         modelState.AddModelError(x.PropertyName, x.ErrorMessage);
     }
 }
 public static void AddModelError(this ModelStateDictionary modelState, List<ServiceError> errors)
 {
     foreach (var error in errors)
     {
         modelState.AddModelError(error.PropertyName, error.PropertyMessage);
     }
 }
Example #17
0
 public static void AddModelErrors(this ModelStateDictionary modelState, IEnumerable<RuleViolation> errors)
 {
     foreach (RuleViolation issue in errors)
     {
         modelState.AddModelError(issue.PropertyName, issue.ErrorMessage);
     }
 }
Example #18
0
 public static void AddRuleViolations(this ModelStateDictionary modelState, IEnumerable<RuleViolation> violations)
 {
     foreach (var violation in violations)
     {
         modelState.AddModelError(violation.Property, violation.Violation);
     }
 }
 public static void AddModelErrors(this ModelStateDictionary state, IEnumerable<ValidationError> errors, string subModelName)
 {
     foreach (var error in errors)
     {
         string propertyName = String.Format("{0}.{1}", subModelName, error.PropertyName);
         state.AddModelError(propertyName, error.ErrorMessage);
     }
 }
 public static void AddValidationErrors(this ModelStateDictionary modelStateDictionary, ValidationException validationException )
 {
     var errorColumns = validationException.Errors.Select(error => new ErrorColumn(error.PropertyName, error.ErrorMessage));
     foreach (var errorColumn in errorColumns)
     {
         modelStateDictionary.AddModelError(errorColumn.Name, errorColumn.Message);
     }
 }
Example #21
0
 public static void AddValidationErrors(this ModelStateDictionary modelstate, ValidationException validationException)
 {
     var validationIssues = validationException.ValidationResult.ValidationIssues;
     foreach (var validationIssue in validationIssues)
     {
         modelstate.AddModelError(validationIssue.PropertyName, validationIssue.Message);
     }
 }
 public static void AddRange(this ModelStateDictionary modelState, IEnumerable<ValidationMessage> messages)
 {
     modelState.Clear();
     foreach (var msg in messages)
     {
         modelState.AddModelError(msg.PropertyName, msg.ErrorMessage);
     }
 }
 public static void AddRange(this ModelStateDictionary modelState, ValidationMessageCollection messageCollection)
 {
     modelState.Clear();
     foreach (var msg in messageCollection.AllValidationMessages)
     {
         modelState.AddModelError(msg.PropertyName, msg.ErrorMessage);
     }
 }
Example #24
0
        public static void AddIdentityErrors(this ModelStateDictionary modelState, IdentityResult result)
        {
            foreach (var error in result.Errors)
            {
                modelState.AddModelError(string.Empty, error.Description);
            }

        }
 public static void AddValidationErrorList(this ModelStateDictionary modelStateDictionary,
                                   List<ValidationResult> validationList)
 {
     foreach (var validationResult in validationList)
     {
         modelStateDictionary.AddModelError(validationResult.FieldName, validationResult.Error);
     }
 }
 public static void AddModelErrors(this ModelStateDictionary state,
     ServiceValidationException exception)
 {
     foreach (var error in exception.Errors)
     {
         state.AddModelError(error.Key, error.Value);
     }
 }
Example #27
0
        public static void FromContext(this ModelStateDictionary modelState, MappingContext context)
        {
            modelState.Clear();

            if (context.GlobalErrors.Count > 0)
                foreach (var p in context.GlobalErrors)
                    foreach (var v in p.Value)
                        modelState.AddModelError(p.Key, v, context.GlobalInputs.TryGetC(p.Key));
        }
        public static void AddRecaptchaErrors(this ModelStateDictionary modelState, RecaptchaResponse recaptchaResponse)
        {
            if (recaptchaResponse?.ErrorCodes == null) return;

            foreach (var errorCode in recaptchaResponse.ErrorCodes)
            {
                modelState.AddModelError("ReCAPTCHA", errorCode.ToString());
            }
        }
Example #29
0
        public static void FromDictionary(this ModelStateDictionary modelState, Dictionary<string, List<string>> errors, NameValueCollection form)
        {
            modelState.Clear();

            if (errors != null)
                foreach (var p in errors)
                    foreach (var v in p.Value)
                        modelState.AddModelError(p.Key, v, form[p.Key]);
        }
 public static void AddValidationExceptionToModel(this ModelStateDictionary model, string prefix,
     ValidationException exception)
 {
     var errors = exception.Errors;
     foreach (var error in errors)
     {
         model.AddModelError(string.Format("{0}.{1}", prefix, error.PropertyName), error.Message);
     }
 }