public static async Task <HttpResponseValidationWrapper <T> > GetBodyAsync <T>(this HttpRequest request) { var body = new HttpResponseValidationWrapper <T>(); var bodyString = await request.ReadAsStringAsync(); body.Value = JsonConvert.DeserializeObject <T>(bodyString); var results = new List <ValidationResult>(); body.IsValid = Validator.TryValidateObject(body.Value, new ValidationContext(body.Value, null, null), results, true); body.ValidationResults = results; return(body); }
public static async Task <HttpResponseValidationWrapper <T> > GetFormAsync <T>(this HttpRequest request) { var instance = new HttpResponseValidationWrapper <T>(); var formCollection = await request.ReadFormAsync(); instance.Value = CopyThingy.Populate <T>(formCollection); var results = new List <ValidationResult>(); instance.IsValid = Validator.TryValidateObject(instance.Value, new ValidationContext(instance.Value, null, null), results, true); instance.ValidationResults = results; return(instance); }