Example #1
0
 /// <summary>
 /// Binds the specified controller action parameter.
 /// </summary>
 /// <param name="controllerActionParameter">The controller action parameter.</param>
 /// <param name="controllerActionRoute">The controller action route.</param>
 public static void Bind(IControllerActionParameter controllerActionParameter, IControllerActionRoute controllerActionRoute)
 {
     foreach (var binder in _binders.Where(x => x.CanBind(controllerActionParameter)))
     {
         binder.Bind(controllerActionParameter, controllerActionRoute);
     }
 }
Example #2
0
 /// <summary>
 /// Binds the parameter to a route
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 /// <param name="controllerActionRoute">The controller action route.</param>
 public void Bind(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute)
 {
     //ignore parameters with null values.
     if (parameter.ParameterValue == null)
     {
         return;
     }
     BindParameter(parameter, controllerActionRoute);
 }
Example #3
0
        protected override void BindParameter(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute)
        {
            var complexModel = parameter.ParameterValue as ComplexModel;

            if (complexModel.Id == null)
            {
                throw new System.ArgumentException("complexModel.Id can not be null.  Did you forget to set it on your source model?");
            }
            controllerActionRoute.SetRouteValue("myid", complexModel.Id);
        }
Example #4
0
        /// <summary>
        /// Binds the parameter to a route.
        /// </summary>
        /// <param name="parameter">The parameter.</param>
        /// <param name="controllerActionRoute">The controller action route.</param>
        protected override void BindParameter(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute)
        {
            if (parameter.ParameterValue is string || parameter.ParameterValue.GetType().IsPrimitive)
            {
                controllerActionRoute.SetQueryStringParameter(parameter.ParameterName, parameter.ParameterValue.ToString());
            }
            else
            {
                //assume we need to pass the model as a query string parameter
                var properties = from p in parameter.ParameterValue.GetType().GetProperties()
                                 where p.GetValue(parameter.ParameterValue, null) != null
                                 select new
                {
                    Name = p.Name,
                    Val  = HttpUtility.UrlEncode(p.GetValue(parameter.ParameterValue, null).ToString())
                };

                foreach (var property in properties)
                {
                    controllerActionRoute.SetQueryStringParameter(property.Name, property.Val);
                }
            }
        }
Example #5
0
 /// <summary>
 /// Determines whether BindingSourceMetadata is of the specified type.
 /// </summary>
 /// <typeparam name="TAttributeType">The type of the attribute type.</typeparam>
 /// <param name="paramter">The paramter.</param>
 /// <returns>
 ///   <c>true</c> if [is binding source of type] [the specified paramter]; otherwise, <c>false</c>.
 /// </returns>
 protected bool IsBindingSourceOfType <TAttributeType>(IControllerActionParameter paramter)
 {
     return(paramter.BindingSourceMetadata?.GetType().Equals(typeof(TAttributeType)) ?? false);
 }
Example #6
0
 /// <summary>
 /// Binds the parameter to a route.
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 /// <param name="controllerActionRoute">The controller action route.</param>
 protected abstract void BindParameter(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute);
Example #7
0
 /// <summary>
 /// Determines whether this instance can bind the specified parameter.
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 /// <returns>
 /// <c>true</c> if this instance can decompose the specified parameter; otherwise, <c>false</c>.
 /// </returns>
 public abstract bool CanBind(IControllerActionParameter parameter);
Example #8
0
 /// <summary>
 /// Determines whether this instance can bind the specified parameter.
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 /// <returns>
 /// <c>true</c> if this instance can decompose the specified parameter; otherwise, <c>false</c>.
 /// </returns>
 public override bool CanBind(IControllerActionParameter parameter)
 {
     return(IsBindingSourceOfType <FromBodyAttribute>(parameter));
 }
Example #9
0
 /// <summary>
 /// Binds the parameter to a route.
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 /// <param name="controllerActionRoute">The controller action route.</param>
 protected override void BindParameter(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute)
 {
     controllerActionRoute.SetModel(parameter.ParameterValue);
 }
Example #10
0
 /// <summary>
 /// Determines whether this instance can bind the specified parameter.
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 /// <returns>
 ///   <c>true</c> if this instance can bind the specified parameter; otherwise, <c>false</c>.
 /// </returns>
 public override bool CanBind(IControllerActionParameter parameter)
 {
     return(parameter.BindingSourceMetadata == null);
 }
Example #11
0
 /// <summary>
 /// Binds the parameter to a route.
 /// </summary>
 /// <param name="parameter">The parameter.</param>
 /// <param name="controllerActionRoute">The controller action route.</param>
 protected override void BindParameter(IControllerActionParameter parameter, IControllerActionRoute controllerActionRoute)
 {
 }
Example #12
0
 public override bool CanBind(IControllerActionParameter parameter)
 {
     return(parameter.ParameterValue is ComplexModel);
 }