/// <summary>
 /// Adds the specified BaseItem to the collection via POST.
 /// </summary>
 /// <param name="baseItem">The BaseItem to add.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
 /// <returns>The created BaseItem.</returns>
 public System.Threading.Tasks.Task <BaseItem> AddAsync(BaseItem baseItem, CancellationToken cancellationToken)
 {
     this.ContentType   = "application/json";
     this.Method        = "POST";
     baseItem.ODataType = string.Concat("#", StringHelper.ConvertTypeToLowerCamelCase(baseItem.GetType().FullName));
     return(this.SendAsync <BaseItem>(baseItem, cancellationToken));
 }
        /// <summary>
        /// Updates the specified BaseItem using PATCH.
        /// </summary>
        /// <param name="baseItemToUpdate">The BaseItem 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 BaseItem.</returns>
        public async System.Threading.Tasks.Task <BaseItem> UpdateAsync(BaseItem baseItemToUpdate, CancellationToken cancellationToken)
        {
            if (baseItemToUpdate.AdditionalData != null)
            {
                if (baseItemToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
                    baseItemToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
                {
                    throw new ClientException(
                              new Error
                    {
                        Code    = GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, baseItemToUpdate.GetType().Name)
                    });
                }
            }
            if (baseItemToUpdate.AdditionalData != null)
            {
                if (baseItemToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
                    baseItemToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
                {
                    throw new ClientException(
                              new Error
                    {
                        Code    = GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, baseItemToUpdate.GetType().Name)
                    });
                }
            }
            this.ContentType = "application/json";
            this.Method      = "PATCH";
            var updatedEntity = await this.SendAsync <BaseItem>(baseItemToUpdate, cancellationToken).ConfigureAwait(false);

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