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)); }
/// <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); }