コード例 #1
0
        private static ResourceContext CreateResourceContext(RouteValueDictionary routeValues,
                                                             IControllerResourceMapping controllerResourceMapping, IResourceContextProvider resourceGraph)
        {
            var controllerName = (string)routeValues["controller"];

            if (controllerName == null)
            {
                return(null);
            }

            var resourceType = controllerResourceMapping.GetAssociatedResource(controllerName);

            return(resourceGraph.GetResourceContext(resourceType));
        }
コード例 #2
0
        /// <summary>
        /// Gets the current entity that we need for serialization and deserialization.
        /// </summary>
        /// <returns></returns>
        private ResourceContext GetCurrentEntity()
        {
            var controllerName = (string)_routeValues["controller"];

            if (controllerName == null)
            {
                return(null);
            }
            var resourceType    = _controllerResourceMapping.GetAssociatedResource(controllerName);
            var requestResource = _resourceGraph.GetResourceContext(resourceType);

            if (requestResource == null)
            {
                return(requestResource);
            }
            if (_routeValues.TryGetValue("relationshipName", out object relationshipName))
            {
                _currentRequest.RequestRelationship = requestResource.Relationships.Single(r => r.PublicRelationshipName == (string)relationshipName);
            }
            return(requestResource);
        }