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

            var    primaryId  = (TId)operation.Resource.GetTypedId();
            object rightValue = GetRelationshipRightValue(operation);

            await _service.SetRelationshipAsync(primaryId, operation.Request.Relationship.PublicName, rightValue, cancellationToken);

            return(null);
        }
        /// <summary>
        /// Performs a complete replacement of a relationship on an existing resource.
        /// Example: PATCH /articles/1/relationships/author HTTP/1.1
        /// Example: PATCH /articles/1/relationships/revisions HTTP/1.1
        /// </summary>
        /// <param name="id">The identifier of the primary resource.</param>
        /// <param name="relationshipName">The relationship for which to perform a complete replacement.</param>
        /// <param name="secondaryResourceIds">The resource or set of resources to assign to the relationship.</param>
        /// <param name="cancellationToken">Propagates notification that request handling should be canceled.</param>
        public virtual async Task <IActionResult> PatchRelationshipAsync(TId id, string relationshipName, [FromBody] object secondaryResourceIds, CancellationToken cancellationToken)
        {
            _traceWriter.LogMethodStart(new { id, relationshipName, secondaryResourceIds });

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

            if (_setRelationship == null)
            {
                throw new RequestMethodNotAllowedException(HttpMethod.Patch);
            }

            await _setRelationship.SetRelationshipAsync(id, relationshipName, secondaryResourceIds, cancellationToken);

            return(NoContent());
        }