public override async Task <object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content,
                                                                IFormatterLogger formatterLogger)
        {
            var      httpContentToFormDataConverter = new HttpContentToFormDataConverter();
            FormData multipartFormData = await httpContentToFormDataConverter.Convert(content);

            readStream.Position = 0;

            IFormDataConverterLogger logger;

            if (formatterLogger != null)
            {
                logger = new FormatterLoggerAdapter(formatterLogger);
            }
            else
            {
                logger = new FormDataConverterLogger();
            }

            var    dataToObjectConverter = new FormDataToObjectConverter(multipartFormData, logger, Settings);
            object result = dataToObjectConverter.Convert(type);

            logger.EnsureNoErrors();

            return(result);
        }
        public async Task <InputFormatterResult> ReadAsync(InputFormatterContext context)
        {
            Type             type;
            IFormatterLogger formatterLogger;

            type            = context.ModelType;
            formatterLogger = null;

            HttpContextToFormDataConverter httpContextToFormDataConverter = new HttpContextToFormDataConverter();
            FormData multipartFormData = await httpContextToFormDataConverter.Convert(context.HttpContext.Request.Form);

            IFormDataConverterLogger logger;

            if (formatterLogger != null)
            {
                logger = new FormatterLoggerAdapter(formatterLogger);
            }
            else
            {
                logger = new FormDataConverterLogger();
            }

            var    dataToObjectConverter = new FormDataToObjectConverter(multipartFormData, logger, Settings);
            object result = dataToObjectConverter.Convert(type);

            logger.EnsureNoErrors();

            return(await InputFormatterResult.SuccessAsync(result));
        }
Ejemplo n.º 3
0
        public ApiResult <PersonModel> PostPersonBindRawFormData(FormData formData)
        {
            var logger = new FormDataConverterLogger();
            var dataToObjectConverter = new FormDataToObjectConverter(formData, logger, Settings);

            var person = (PersonModel)dataToObjectConverter.Convert(typeof(PersonModel));

            logger.EnsureNoErrors();

            return(GetApiResult(person));
        }
        public override async Task <object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content,
                                                                IFormatterLogger formatterLogger)
        {
            var httpContentToFormDataConverter = new HttpContentToFormDataConverter();
            var multipartFormData = await httpContentToFormDataConverter.Convert(content);

            var dataToObjectConverter = new FormDataToObjectConverter(multipartFormData);
            var result = dataToObjectConverter.Convert(type);


            return(result);
        }