예제 #1
0
        public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap)
        {
            string requestMethod          = controllerContext.Request.Method.ToString().ToUpperInvariant();
            TestControllerContext context = new TestControllerContext(controllerContext);
#endif
            if (odataPath.PathTemplate == "~/entityset/key/navigation/$ref" && requestMethod == "GET")
            {
                KeySegment keyValueSegment = odataPath.Segments[1] as KeySegment;
                context.AddKeyValueToRouteData(keyValueSegment);
                NavigationPropertyLinkSegment navigationLinkSegment = odataPath.Segments[2] as NavigationPropertyLinkSegment;
                IEdmNavigationProperty        navigationProperty    = navigationLinkSegment.NavigationProperty;
                IEdmEntityType declaredType = navigationProperty.DeclaringType as IEdmEntityType;

                string action = requestMethod + "LinksFor" + navigationProperty.Name + "From" + declaredType.Name;
                return(actionMap.Contains(action) ? action : requestMethod + "LinksFor" + navigationProperty.Name);
            }

#if NETCORE
            return(base.SelectAction(routeContext, controllerResult, actionDescriptors));
#else
            return(base.SelectAction(odataPath, controllerContext, actionMap));
#endif
        }
예제 #2
0
        /// <inheritdoc/>
        protected override string SelectAction(string requestMethod, ODataPath odataPath, TestControllerContext controllerContext, IList <string> actionList)
        {
            if (odataPath.PathTemplate == "~/entityset/key/property" || odataPath.PathTemplate == "~/entityset/key/cast/property")
            {
                var segment     = odataPath.Segments.Last() as PropertySegment;
                var property    = segment.Property;
                var declareType = property.DeclaringType as IEdmEntityType;
                if (declareType != null)
                {
                    var key = odataPath.Segments[1] as KeySegment;
                    controllerContext.AddKeyValueToRouteData(key);
                    controllerContext.RouteData.Add("property", property.Name);
                    string prefix = ODataHelper.GetHttpPrefix(requestMethod);
                    if (string.IsNullOrEmpty(prefix))
                    {
                        return(null);
                    }
                    string action = prefix + "Property" + "From" + declareType.Name;
                    return(actionList.Contains(action) ? action : prefix + "Property");
                }
            }

            return(null);
        }
예제 #3
0
 /// <inheritdoc/>
 /// <remarks>This signature uses types that are AspNetCore-specific.</remarks>
 public override string SelectAction(RouteContext routeContext, SelectControllerResult controllerResult, IEnumerable <ControllerActionDescriptor> actionDescriptors)
 {
     string                requestMethod = routeContext.HttpContext.Request.Method;
     ODataPath             odataPath     = routeContext.HttpContext.ODataFeature().Path;
     TestControllerContext context       = new TestControllerContext(routeContext);
     IList <string>        actionMap     = actionDescriptors.Select(a => a.ActionName).Distinct().ToList();
예제 #4
0
 /// <inheritdoc/>
 protected override string SelectAction(string requestMethod, ODataPath odataPath, TestControllerContext controllerContext, IList <string> actionList)
 {
     if (requestMethod == "DELETE" &&
         odataPath.PathTemplate == "~/entityset")
     {
         string actionName = "Delete";
         if (actionList.Contains(actionName))
         {
             return(actionName);
         }
     }
     return(null);
 }