AddFieldMismatchValidationError() public method

Adds the field mismatch validation error.
public AddFieldMismatchValidationError ( string fieldName ) : void
fieldName string Name of the field.
return void
Esempio n. 1
0
        /// <summary>
        /// Adds the model state errors.
        /// </summary>
        /// <param name="modelState">State of the model.</param>
        /// <returns>The ApiResult from Model State.</returns>
        public static ApiResult FromModelStateErrors(ModelStateDictionary modelState)
        {
            var result = new ApiResult();

            foreach (var(key, value) in modelState.Where(x => x.Value.Errors.Any()))
            {
                var error = value.Errors.First();

                switch (error.ErrorMessage)
                {
                case nameof(ApiErrorCode.FieldRequired):
                    result.AddFieldRequiredValidationError(key);
                    break;

                case nameof(ApiErrorCode.FieldMismatch):
                    result.AddFieldMismatchValidationError(key);
                    break;

                default:
                    result.AddGenericFieldValidationError(key, error.ErrorMessage);
                    break;
                }
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the model state errors.
        /// </summary>
        /// <param name="modelState">State of the model.</param>
        /// <returns></returns>
        public static ApiResult FromModelStateErrors(ModelStateDictionary modelState)
        {
            var result = new ApiResult();

            foreach (var state in modelState.Where(x => x.Value.Errors.Any()))
            {
                var error = state.Value.Errors.First();

                if (error.ErrorMessage.Equals(nameof(ApiErrorCode.FieldRequired)))
                {
                    result.AddFieldRequiredValidationError(state.Key);
                }
                else if (error.ErrorMessage.Equals(nameof(ApiErrorCode.FieldMismatch)))
                {
                    result.AddFieldMismatchValidationError(state.Key);
                }
                else
                {
                    result.AddGenericFieldValidationError(state.Key, error.ErrorMessage);
                }
            }

            return(result);
        }