コード例 #1
0
        public static SuccessResponse <ValidationErrorResponse> RequestResponse(List <KeyValuePair <string, string> > errorDictionary)
        {
            var validationModel = new List <ValidationModel>();

            foreach (var error in errorDictionary)
            {
                validationModel.Add(new ValidationModel
                {
                    Code    = StringFormatter.PascalCaseConverter(error.Key),
                    Message = error.Value
                });
            }

            var validationResponse = new ValidationErrorResponse
            {
                Errors = validationModel
            };

            return(new SuccessResponse <ValidationErrorResponse>
            {
                Data = validationResponse,
                ResponseCode = "E002",
                ResponseMessage = "You have supplied an invalid or incomplete information. Kindly check your input and try again."
            });
        }
コード例 #2
0
        public static SuccessResponse <ValidationErrorResponse> RequestResponse(ModelStateDictionary modelState)
        {
            List <ValidationModel> validationModel = new List <ValidationModel>();

            foreach (var item in modelState)
            {
                if (item.Value.Errors.Count != 0)
                {
                    foreach (var error in item.Value.Errors)
                    {
                        validationModel.Add(new ValidationModel
                        {
                            Code    = StringFormatter.PascalCaseConverter(item.Key),
                            Message = error.ErrorMessage
                        });
                    }
                }
            }

            var validationResponse = new ValidationErrorResponse
            {
                Errors = validationModel
            };

            return(new SuccessResponse <ValidationErrorResponse>
            {
                Data = validationResponse,
                ResponseCode = "E001",
                ResponseMessage = "You have supplied an invalid or incomplete information. Kindly check your input and try again.s"
            });
        }