/// <inheritdoc />
        public virtual async Task <OperationContainer> ProcessAsync(OperationContainer operation, CancellationToken cancellationToken)
        {
            ArgumentGuard.NotNull(operation, nameof(operation));

            var primaryId = (TId)operation.Resource.GetTypedId();
            ISet <IIdentifiable> secondaryResourceIds = operation.GetSecondaryResources();

            await _service.AddToToManyRelationshipAsync(primaryId, operation.Request.Relationship.PublicName, secondaryResourceIds, cancellationToken);

            return(null);
        }
        /// <summary>
        /// Adds resources to a to-many relationship.
        /// Example: POST /articles/1/revisions HTTP/1.1
        /// </summary>
        /// <param name="id">The identifier of the primary resource.</param>
        /// <param name="relationshipName">The relationship to add resources to.</param>
        /// <param name="secondaryResourceIds">The set of resources to add to the relationship.</param>
        /// <param name="cancellationToken">Propagates notification that request handling should be canceled.</param>
        public virtual async Task <IActionResult> PostRelationshipAsync(TId id, string relationshipName, [FromBody] ISet <IIdentifiable> secondaryResourceIds, CancellationToken cancellationToken)
        {
            _traceWriter.LogMethodStart(new { id, relationshipName, secondaryResourceIds });

            ArgumentGuard.NotNull(relationshipName, nameof(relationshipName));
            ArgumentGuard.NotNull(secondaryResourceIds, nameof(secondaryResourceIds));

            if (_addToRelationship == null)
            {
                throw new RequestMethodNotAllowedException(HttpMethod.Post);
            }

            await _addToRelationship.AddToToManyRelationshipAsync(id, relationshipName, secondaryResourceIds, cancellationToken);

            return(NoContent());
        }
Beispiel #3
0
        /// <inheritdoc />
        public virtual async Task <OperationContainer> ProcessAsync(OperationContainer operation,
                                                                    CancellationToken cancellationToken)
        {
            if (operation == null)
            {
                throw new ArgumentNullException(nameof(operation));
            }

            var primaryId            = (TId)operation.Resource.GetTypedId();
            var secondaryResourceIds = operation.GetSecondaryResources();

            await _service.AddToToManyRelationshipAsync(primaryId, operation.Request.Relationship.PublicName,
                                                        secondaryResourceIds, cancellationToken);

            return(null);
        }