示例#1
0
        public async Task BindModelAsync(ModelBindingContext bindingContext)
        {
            if (bindingContext == null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }
            var jsonString = await ReadBodyAsString(bindingContext);

            var json = JObject.Parse(jsonString);
            var customEntityDefinitionCodeProperty = json.GetValue("CustomEntityDefinitionCode", StringComparison.OrdinalIgnoreCase);

            JsonConverter dataModelConverter;

            if (customEntityDefinitionCodeProperty == null)
            {
                dataModelConverter = new NullCustomEntityDataModelJsonConverter();
            }
            else
            {
                dataModelConverter = GetDataTypeConverter(customEntityDefinitionCodeProperty.Value <string>());
            }

            var result = JsonConvert.DeserializeObject(jsonString, bindingContext.ModelType, dataModelConverter);

            bindingContext.Result = ModelBindingResult.Success(result);
        }
示例#2
0
        public bool BindModel(System.Web.Http.Controllers.HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            var jsonString = actionContext.Request.Content.ReadAsStringAsync().Result;
            var json       = JObject.Parse(jsonString);
            var customEntityDefinitionCodeProperty = json.GetValue("CustomEntityDefinitionCode", StringComparison.OrdinalIgnoreCase);

            JsonConverter dataModelConverter;

            if (customEntityDefinitionCodeProperty == null)
            {
                dataModelConverter = new NullCustomEntityDataModelJsonConverter();
            }
            else
            {
                dataModelConverter = GetModuleDataTypeConverter(customEntityDefinitionCodeProperty.Value <string>());
            }

            var result = JsonConvert.DeserializeObject(jsonString, bindingContext.ModelType, dataModelConverter);

            bindingContext.Model = result;

            return(true);
        }