예제 #1
0
        private void PopulateModelErrors(ModelStateDictionary modelState)
        {
            foreach (KeyValuePair <string, ModelState> validationItem in modelState)
            {
                string propertyName = StripOutModelName(validationItem.Key);

                BadRequestError badRequestError;
                if (!ModelErrors.TryGetValue(propertyName, out badRequestError))
                {
                    badRequestError = new BadRequestError();
                    ModelErrors.Add(propertyName, badRequestError);
                }

                foreach (ModelError err in validationItem.Value.Errors)
                {
                    if (!string.IsNullOrWhiteSpace(err.ErrorMessage))
                    {
                        badRequestError.AddError(err.ErrorMessage);
                    }

                    if (err.Exception != null)
                    {
                        badRequestError.AddException(err.Exception.Message);
                    }
                }
            }
        }
예제 #2
0
        public static BadRequestResponse Create(IEnumerable <string> validationErrors)
        {
            var             response = new BadRequestResponse();
            BadRequestError badRequestError;

            if (!response.ModelErrors.TryGetValue(string.Empty, out badRequestError))
            {
                badRequestError = new BadRequestError();
                response.ModelErrors.Add(string.Empty, badRequestError);
            }

            foreach (string err in validationErrors)
            {
                badRequestError.AddError(err);
            }

            return(response);
        }