Пример #1
0
        /// <inheritdoc/>
        internal static string SelectActionImpl(ODataPath odataPath, IWebApiControllerContext controllerContext,
                                                IWebApiActionMap actionMap)
        {
            OperationImportSegment operationImportSegment = null;

            if (odataPath.PathTemplate == "~/unboundfunction" &&
                ODataRequestMethod.Get == controllerContext.Request.Method)
            {
                // The same function name may be used multiple times within a schema, each with a different set of parameters.
                // For unbound overloads the combination of the function name and the unordered set of parameter names
                // MUST identify a particular function overload.
                operationImportSegment = (OperationImportSegment)odataPath.Segments[0];
            }
            else if (odataPath.PathTemplate == "~/unboundaction" &&
                     ODataRequestMethod.Post == controllerContext.Request.Method)
            {
                // The same action name may be used multiple times within a schema provided there is at most one unbound overload
                operationImportSegment = (OperationImportSegment)odataPath.Segments[0];
            }

            string actionName = SelectAction(operationImportSegment, actionMap);

            if (actionName != null)
            {
                controllerContext.AddFunctionParameterToRouteData(operationImportSegment);
                return(actionName);
            }

            return(null);
        }
Пример #2
0
        internal static string SelectActionImpl(ODataPath odataPath, IWebApiControllerContext controllerContext,
                                                IWebApiActionMap actionMap)
        {
            if (ODataRequestMethod.Get == controllerContext.Request.GetRequestMethodOrPreflightMethod())
            {
                string           actionName = null;
                OperationSegment function   = null;
                switch (odataPath.PathTemplate)
                {
                case "~/entityset/key/cast/function":
                case "~/entityset/key/function":
                    function   = odataPath.Segments.Last() as OperationSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
                    if (actionName != null)
                    {
                        controllerContext.AddKeyValueToRouteData((KeySegment)odataPath.Segments[1]);
                    }
                    break;

                case "~/entityset/key/cast/function/$count":
                case "~/entityset/key/function/$count":
                    function   = odataPath.Segments[odataPath.Segments.Count - 2] as OperationSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
                    if (actionName != null)
                    {
                        controllerContext.AddKeyValueToRouteData((KeySegment)odataPath.Segments[1]);
                    }
                    break;

                case "~/entityset/cast/function":
                case "~/entityset/function":
                    function   = odataPath.Segments.Last() as OperationSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: true);
                    break;

                case "~/entityset/cast/function/$count":
                case "~/entityset/function/$count":
                    function   = odataPath.Segments[odataPath.Segments.Count - 2] as OperationSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: true);
                    break;

                case "~/singleton/function":
                case "~/singleton/cast/function":
                    function   = odataPath.Segments.Last() as OperationSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
                    break;

                case "~/singleton/function/$count":
                case "~/singleton/cast/function/$count":
                    function   = odataPath.Segments[odataPath.Segments.Count - 2] as OperationSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
                    break;
                }

                if (actionName != null)
                {
                    controllerContext.AddFunctionParameterToRouteData(function);
                    return(actionName);
                }
            }

            return(null);
        }