Exemplo n.º 1
0
        private static bool TrySetPropertyFromRequestUrl(PropertyBindingContext pbc, RequestBindingContext context)
        {
            if (!context.Request.RouteValues.TryGetValue(pbc.Name, out var paramValue))
            {
                return(false);
            }

            var propertyValue = Convert.ChangeType(paramValue, pbc.CommandProperty.PropertyType);

            return(context.TrySetCommandProperty(pbc, propertyValue));
        }
Exemplo n.º 2
0
        private static bool TrySetPropertyFromForm(PropertyBindingContext pbc, RequestBindingContext context)
        {
            var formValues = context.FormData[pbc.Name];

            if (formValues.Count < 1)
            {
                return(false);
            }

            return(context.TrySetCommandProperty(pbc, formValues[0]));
        }
Exemplo n.º 3
0
        private static bool TrySetPropertyFromRequestBody(PropertyBindingContext pbc, RequestBindingContext context)
        {
            var bodyProperty = context.BodyObject?.Property(pbc.Name, StringComparison.OrdinalIgnoreCase);

            if (bodyProperty == null)
            {
                return(false);
            }

            var commandPropertyType = pbc.CommandProperty.PropertyType;

            object propertyValue;

            try
            {
                propertyValue = bodyProperty.Value.ToObject(commandPropertyType);
            }
            catch
            {
                return(false);
            }

            return(context.TrySetCommandProperty(pbc, propertyValue));
        }