예제 #1
0
 /// <summary>
 /// Adds the specified Attachment to the collection via POST.
 /// </summary>
 /// <param name="attachment">The Attachment to add.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
 /// <returns>The created Attachment.</returns>
 public System.Threading.Tasks.Task <Attachment> AddAsync(Attachment attachment, CancellationToken cancellationToken)
 {
     this.ContentType     = "application/json";
     this.Method          = "POST";
     attachment.ODataType = string.Concat("#", StringHelper.ConvertTypeToLowerCamelCase(attachment.GetType().FullName));
     return(this.SendAsync <Attachment>(attachment, cancellationToken));
 }
예제 #2
0
        /// <summary>
        /// Updates the specified Attachment using PATCH.
        /// </summary>
        /// <param name="attachmentToUpdate">The Attachment to update.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <exception cref="ClientException">Thrown when an object returned in a response is used for updating an object in Microsoft Graph.</exception>
        /// <returns>The updated Attachment.</returns>
        public async System.Threading.Tasks.Task <Attachment> UpdateAsync(Attachment attachmentToUpdate, CancellationToken cancellationToken)
        {
            if (attachmentToUpdate.AdditionalData != null)
            {
                if (attachmentToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
                    attachmentToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
                {
                    throw new ClientException(
                              new Error
                    {
                        Code    = GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, attachmentToUpdate.GetType().Name)
                    });
                }
            }
            if (attachmentToUpdate.AdditionalData != null)
            {
                if (attachmentToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
                    attachmentToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
                {
                    throw new ClientException(
                              new Error
                    {
                        Code    = GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, attachmentToUpdate.GetType().Name)
                    });
                }
            }
            this.ContentType = "application/json";
            this.Method      = "PATCH";
            var updatedEntity = await this.SendAsync <Attachment>(attachmentToUpdate, cancellationToken).ConfigureAwait(false);

            this.InitializeCollectionProperties(updatedEntity);
            return(updatedEntity);
        }