Ejemplo n.º 1
0
        //-------------------- COMMON LINK PROPERTY GENERATION METHODS ----------------------

        public ActionUrlLink BuildActionUrlLink <TController>(Expression <Action <TController, TResource> > action)
            where TController : Controller
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action), "Controller Action selector not specified.");
            }

            var actionLink     = new ActionUrlLink();
            var actionSelector = new ActionUrlSelector <TController, TResource>(actionLink, action);

            actionSelector.SetRouteInfo();
            return(actionLink);
        }
Ejemplo n.º 2
0
        // Called for action link containing information based on an expression, specified at compile time, selecting a
        // controller's action method.  The expression also specifies which resource properties should be used for
        // the action's route parameters.
        private Link SetLinkUrl(ResourceContext context, ActionUrlLink actionLink)
        {
            string controllerSuffix = context.RestModule.GetControllerSuffix();
            string controllerName   = actionLink.Controller.Replace(controllerSuffix, "");

            var routeValues = GetModelRouteValues(context, actionLink);
            var link        = new Link
            {
                // Delegate to ASP.NET Core to get the URL corresponding to the route-values.
                Href      = context.UrlHelper.Action(actionLink.Action, controllerName, routeValues),
                Templated = false,
                Methods   = actionLink.Methods.ToArray()
            };

            UpdateLinkDescriptorsAndResource(context, actionLink, link);
            return(link);
        }
Ejemplo n.º 3
0
        // For each controller action argument execute the cached expression on the resource
        // to get the corresponding resource property value.
        private Dictionary <string, object> GetModelRouteValues(ResourceContext context, ActionUrlLink halLink)
        {
            var modelRouteValues = new Dictionary <string, object>(halLink.RouteValues.Count);

            foreach (ActionParamValue actionParam in halLink.RouteValues)
            {
                modelRouteValues[actionParam.ActionParamName] = actionParam.GetModelPropValue(context.Resource);
            }
            return(modelRouteValues);
        }