Exemplo n.º 1
0
        public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            // MS_QueryNameValuePairs contains key value pair representation of the query parameters passed to in the request.
            if (actionContext.Request.Properties.ContainsKey("MS_QueryNameValuePairs"))
            {
                bindingContext.Model = _objectConverter.ToObject <T>(
                    (ICollection <KeyValuePair <string, string> >)actionContext.Request.Properties["MS_QueryNameValuePairs"]);
            }
            else
            {
                bindingContext.Model = new T();
            }

            // This should be true otherwise the model will be null.
            return(true);
        }
        public object NullSafeGet(IDataReader rs, string[] names, object owner)
        {
            var valueToGet = NHibernateUtil.StringClob.NullSafeGet(rs, names[0]);

            if (valueToGet == null || valueToGet.ToString() == String.Empty)
            {
                return(null);
            }
            var parts = valueToGet.ToString().Split(new [] { "~~" }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length < 2)
            {
                return(null);
            }
            var type = Type.GetType(parts[0]);
            var val  = parts[1];

            return(_converter.ToObject(type, val));
        }
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            if (bindingContext == null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }

            if (bindingContext.HttpContext.Request.QueryString.HasValue)
            {
                var queryParameters = bindingContext.HttpContext.Request.Query.ToDictionary(pair => pair.Key, pair => pair.Value.ToString());

                bindingContext.Model = _objectConverter.ToObject <T>(queryParameters);
            }
            else
            {
                bindingContext.Model = new T();
            }

            bindingContext.Result = ModelBindingResult.Success(bindingContext.Model);

            // This should be true otherwise the model will be null.
            return(Task.CompletedTask);
        }