Пример #1
0
        public static IServiceCollection ConfigureValidationModel(this IServiceCollection services)
        {
            services.Configure <ApiBehaviorOptions>(options =>
            {
                var previous = options.InvalidModelStateResponseFactory;
                options.InvalidModelStateResponseFactory = context =>
                {
                    var result   = (BadRequestObjectResult)previous(context);
                    result.Value = ResponseDTO.Create <object>(null, "There were validation errors", context.ModelState.Values.SelectMany(v => v.Errors));

                    return(result);
                };
            });
            return(services);
        }
Пример #2
0
 public override OkObjectResult Ok(object value) => base.Ok(ResponseDTO.Create(value));