コード例 #1
0
 public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup <string, HttpActionDescriptor> actionMap)
 {
     if ((odataPath.PathTemplate == "~/entityset/key/navigation") || (odataPath.PathTemplate == "~/entityset/key/cast/navigation"))
     {
         NavigationPropertySegment segment            = odataPath.Segments.Last <ODataPathSegment>() as NavigationPropertySegment;
         IEdmNavigationProperty    navigationProperty = segment.NavigationProperty;
         IEdmEntityType            declaringType      = navigationProperty.DeclaringType as IEdmEntityType;
         if (declaringType != null)
         {
             string prefix = ODataHelper.GetHttpPrefix(controllerContext.Request.Method.ToString());
             if (string.IsNullOrEmpty(prefix))
             {
                 return(null);
             }
             KeySegment segment2 = odataPath.Segments[1] as KeySegment;
             controllerContext.AddKeyValueToRouteData(segment2);
             string key = prefix + navigationProperty.Name + "On" + declaringType.Name;
             return(actionMap.Contains(key) ? key : (prefix + navigationProperty.Name));
         }
     }
     return(null);
 }
コード例 #2
0
 /// <inheritdoc/>
 protected override string SelectAction(string requestMethod, ODataPath odataPath, TestControllerContext controllerContext, IList <string> actionList)
 {
     if ((odataPath.PathTemplate == "~/entityset/key/navigation") || (odataPath.PathTemplate == "~/entityset/key/cast/navigation"))
     {
         NavigationPropertySegment segment            = odataPath.Segments.Last <ODataPathSegment>() as NavigationPropertySegment;
         IEdmNavigationProperty    navigationProperty = segment.NavigationProperty;
         IEdmEntityType            declaringType      = navigationProperty.DeclaringType as IEdmEntityType;
         if (declaringType != null)
         {
             string prefix = ODataHelper.GetHttpPrefix(requestMethod);
             if (string.IsNullOrEmpty(prefix))
             {
                 return(null);
             }
             KeySegment segment2 = odataPath.Segments[1] as KeySegment;
             controllerContext.AddKeyValueToRouteData(segment2);
             string key = prefix + navigationProperty.Name + "On" + declaringType.Name;
             return(actionList.Contains(key) ? key : (prefix + navigationProperty.Name));
         }
     }
     return(null);
 }
コード例 #3
0
        public override string SelectAction(System.Web.Http.OData.Routing.ODataPath odataPath, System.Web.Http.Controllers.HttpControllerContext controllerContext, ILookup <string, System.Web.Http.Controllers.HttpActionDescriptor> actionMap)
        {
            if (odataPath.PathTemplate == "~/entityset/key/property" || odataPath.PathTemplate == "~/entityset/key/cast/property")
            {
                var segment     = odataPath.Segments.Last() as PropertyAccessPathSegment;
                var property    = segment.Property;
                var declareType = property.DeclaringType as IEdmEntityType;
                if (declareType != null)
                {
                    var key = odataPath.Segments[1] as KeyValuePathSegment;
                    controllerContext.RouteData.Values.Add(ODataRouteConstants.Key, key.Value);
                    string prefix = ODataHelper.GetHttpPrefix(controllerContext.Request.Method.ToString());
                    if (string.IsNullOrEmpty(prefix))
                    {
                        return(null);
                    }
                    string action = prefix + property.Name + "From" + declareType.Name;
                    return(actionMap.Contains(action) ? action : prefix + property.Name);
                }
            }

            return(null);
        }
コード例 #4
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);
                    string prefix = ODataHelper.GetHttpPrefix(requestMethod);
                    if (string.IsNullOrEmpty(prefix))
                    {
                        return(null);
                    }
                    string action = prefix + property.Name + "From" + declareType.Name;
                    return(actionList.Contains(action) ? action : prefix + property.Name);
                }
            }

            return(null);
        }