public SingleResource CreateResourceRepresentation(
            object objectGraph,
            IResourceMapping resourceMapping,
            Context context)
        {
            var result = new SingleResource();

            result.Id         = resourceMapping.IdGetter(objectGraph).ToString();
            result.Type       = resourceMapping.ResourceType;
            result.Attributes = resourceMapping.GetAttributes(objectGraph, configuration.GetJsonSerializerSettings());
            result.Links      = GetObjectLinkData(objectGraph);
            result.Links.Add("self", linkBuilder.FindResourceSelfLink(context, result.Id, resourceMapping));
            result.MetaData = GetObjectMetadata(objectGraph);

            if (resourceMapping.Relationships.Any())
            {
                result.Relationships = CreateRelationships(objectGraph, result.Id, resourceMapping, context);
            }

            return(result);
        }
Пример #2
0
        public SingleResource CreateResourceRepresentation(
            object objectGraph,
            IResourceMapping resourceMapping,
            Context context)
        {
            var result = new SingleResource();

            result.Id         = resourceMapping.IdGetter(objectGraph).ToString();
            result.Type       = resourceMapping.ResourceType;
            result.Attributes = resourceMapping.GetAttributes(objectGraph);
            result.Links      = new Dictionary <string, ILink>()
            {
                { "self", linkBuilder.FindResourceSelfLink(context, result.Id, resourceMapping) }
            };

            if (resourceMapping.Relationships.Any())
            {
                result.Relationships = CreateRelationships(objectGraph, result.Id, resourceMapping, context);
            }

            return(result);
        }