internal DomData SetDomData(ResourceIdentifier apiResourceIdentifier, Type clrResourceType)
        {
            Contract.Requires(apiResourceIdentifier != null);
            Contract.Requires(clrResourceType != null);

            // Validation
            this.ValidateDataDoesNotExist();

            // Add the one allowed DOM data node to the DOM document node.
            var domData = this.CreateAndAddNode(() => DomData.Create());

            // Add the one allowed DOM resource identifier node to the DOM document node.
            var domReadOnlyResourceIdentifier = domData.CreateAndAddNode(() => DomReadOnlyResourceIdentifier.Create(apiResourceIdentifier, clrResourceType));

            return(domData);
        }
Example #2
0
        private static DomReadOnlyResourceIdentifier AddDomReadOnlyResourceIdentifier(DomDocument domDocument, IContainerNode <DomNodeType> domParentNode, ResourceIdentifier apiResourceIdentifier)
        {
            Contract.Requires(domDocument != null);
            Contract.Requires(domParentNode != null);
            Contract.Requires(apiResourceIdentifier != null);

            // Find metadata based on the JsonApi resource.
            var apiResourceType = apiResourceIdentifier.Type;
            var resourceType    = domDocument.ServiceModel.GetResourceType(apiResourceType);
            var clrResourceType = resourceType.ClrType;

            // Create/Add DOM read-only resource identifier node to the parent node.
            var domReadOnlyResourceIdentifier = domParentNode.CreateAndAddNode(() => DomReadOnlyResourceIdentifier.Create(apiResourceIdentifier, clrResourceType));

            return(domReadOnlyResourceIdentifier);
        }
        internal DomDataCollection SetDomDataCollection(IEnumerable <ResourceIdentifier> apiResourceIdentifierCollection, Type clrResourceType)
        {
            Contract.Requires(apiResourceIdentifierCollection != null);
            Contract.Requires(clrResourceType != null);

            // Validation
            this.ValidateDataDoesNotExist();

            // Add the one allowed DOM data collection node to the DOM document node.
            var domDataCollection = this.CreateAndAddNode(() => DomDataCollection.Create());

            // Add the many allowed DOM resource identifier nodes to the DOM document node.
            var domReadOnlyResourceIdentifierCollection =
                apiResourceIdentifierCollection.Select(x => domDataCollection.CreateAndAddNode(() => DomReadOnlyResourceIdentifier.Create(x, clrResourceType)))
                .ToList();

            return(domDataCollection);
        }