AddParent() public méthode

Adds additional parent to data with specified data_id. If remove_other is True, all other parents of specified Data Object will be removed. The collection_id/collection_key parameter means that one can use either one of them - collection_id or collection_key. User API key usage permitted. Data Object that parent is added to is required to be in a container with an update_data permission or (or update_own_data if it is associated with current user). Also, parent itself is required to be in a container with a (read_data permission or read_own_data if it is associated with current user).
public AddParent ( string projectId, string dataId, string parentId, string collectionId = null, string collectionKey = null, bool removeOther = false ) : Task
projectId string Project id.
dataId string Data Object id.
parentId string Parent id to add.
collectionId string Collection id defining collection containing data.
collectionKey string Collection key defining collection containing data.
removeOther bool If true, will remove all other parents. Default value: False.
Résultat Task
        public async Task AddParent_ByCollectionKey(DataObjectSyncanoClient client)
        {
            //given
            var newParentRequest = new DataObjectDefinitionRequest();
            newParentRequest.ProjectId = TestData.ProjectId;
            newParentRequest.CollectionId = TestData.CollectionId;
            var parentObject = await client.New(newParentRequest);

            var newChildRequest = new DataObjectDefinitionRequest();
            newChildRequest.ProjectId = TestData.ProjectId;
            newChildRequest.CollectionId = TestData.CollectionId;
            var childObject = await client.New(newChildRequest);

            //when
            var result =
                await
                    client.AddParent(TestData.ProjectId, childObject.Id, parentObject.Id,
                        collectionKey: TestData.CollectionKey);

            var getResult =
                await
                    client.GetOne(TestData.ProjectId, TestData.CollectionId, dataId: parentObject.Id,
                        includeChildren: true);

            //then
            result.ShouldBeTrue();
            getResult.Children.ShouldNotBeEmpty();
            getResult.Children[0].Id.ShouldEqual(childObject.Id);

            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }
        public async Task AddParent_WithInvalidChildId_ThrowsException(DataObjectSyncanoClient client)
        {
            //given
            var newParentRequest = new DataObjectDefinitionRequest();
            newParentRequest.ProjectId = TestData.ProjectId;
            newParentRequest.CollectionId = TestData.CollectionId;
            var parentObject = await client.New(newParentRequest);

            var newChildRequest = new DataObjectDefinitionRequest();
            newChildRequest.ProjectId = TestData.ProjectId;
            newChildRequest.CollectionId = TestData.CollectionId;
            await client.New(newChildRequest);

            try
            {
                //when
                await
                    client.AddParent(TestData.ProjectId, "abc", parentObject.Id,
                        TestData.CollectionId);
                throw new Exception("AddChild should throw an exception");
            }
            catch (Exception e)
            {
                //then
                e.ShouldBeType<SyncanoException>();
            }
            //cleanup
            var deleteRequest = new DataObjectSimpleQueryRequest();
            deleteRequest.ProjectId = TestData.ProjectId;
            deleteRequest.CollectionId = TestData.CollectionId;
            await client.Delete(deleteRequest);
        }