Box.V2.Managers.BoxCollectionsManager.CreateOrDeleteCollectionsForFileAsync C# (CSharp) Method

CreateOrDeleteCollectionsForFileAsync() public method

To add or remove an item from a collection, you do a PUT on that item and change the list of collections it belongs to.
public CreateOrDeleteCollectionsForFileAsync ( string fileId, BoxCollectionsRequest collectionsRequest ) : Task
fileId string Id of the file.
collectionsRequest Box.V2.Models.BoxCollectionsRequest The request which contains collections ids
return Task
        public async Task<BoxFile> CreateOrDeleteCollectionsForFileAsync(string fileId, BoxCollectionsRequest collectionsRequest)
        {
            fileId.ThrowIfNullOrWhiteSpace("fileId");
            collectionsRequest.ThrowIfNull("collectionsRequest")
                .Collections.ThrowIfNull("collectionsRequest.Collections");

            foreach (var collection in collectionsRequest.Collections)
            {
                collection.Type = null;
            }

            BoxRequest request = new BoxRequest(_config.FilesEndpointUri, fileId)
                .Method(RequestMethod.Put)
                .Payload(_converter.Serialize(collectionsRequest));

            IBoxResponse<BoxFile> response = await ToResponseAsync<BoxFile>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }