/// <summary>
 /// Adds the specified AccessPackageResourceRoleScope to the collection via POST.
 /// </summary>
 /// <param name="accessPackageResourceRoleScope">The AccessPackageResourceRoleScope to add.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
 /// <returns>The created AccessPackageResourceRoleScope.</returns>
 public System.Threading.Tasks.Task <AccessPackageResourceRoleScope> AddAsync(AccessPackageResourceRoleScope accessPackageResourceRoleScope, CancellationToken cancellationToken)
 {
     this.ContentType = "application/json";
     this.Method      = "POST";
     return(this.SendAsync <AccessPackageResourceRoleScope>(accessPackageResourceRoleScope, cancellationToken));
 }
 /// <summary>
 /// Adds the specified AccessPackageResourceRoleScope to the collection via POST.
 /// </summary>
 /// <param name="accessPackageResourceRoleScope">The AccessPackageResourceRoleScope to add.</param>
 /// <returns>The created AccessPackageResourceRoleScope.</returns>
 public System.Threading.Tasks.Task <AccessPackageResourceRoleScope> AddAsync(AccessPackageResourceRoleScope accessPackageResourceRoleScope)
 {
     return(this.AddAsync(accessPackageResourceRoleScope, CancellationToken.None));
 }
 /// <summary>
 /// Initializes any collection properties after deserialization, like next requests for paging.
 /// </summary>
 /// <param name="accessPackageResourceRoleScopeToInitialize">The <see cref="AccessPackageResourceRoleScope"/> with the collection properties to initialize.</param>
 private void InitializeCollectionProperties(AccessPackageResourceRoleScope accessPackageResourceRoleScopeToInitialize)
 {
 }
        /// <summary>
        /// Creates the specified AccessPackageResourceRoleScope using POST.
        /// </summary>
        /// <param name="accessPackageResourceRoleScopeToCreate">The AccessPackageResourceRoleScope to create.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>The created AccessPackageResourceRoleScope.</returns>
        public async System.Threading.Tasks.Task <AccessPackageResourceRoleScope> CreateAsync(AccessPackageResourceRoleScope accessPackageResourceRoleScopeToCreate, CancellationToken cancellationToken)
        {
            this.ContentType = "application/json";
            this.Method      = "POST";
            var newEntity = await this.SendAsync <AccessPackageResourceRoleScope>(accessPackageResourceRoleScopeToCreate, cancellationToken).ConfigureAwait(false);

            this.InitializeCollectionProperties(newEntity);
            return(newEntity);
        }
        /// <summary>
        /// Updates the specified AccessPackageResourceRoleScope using PATCH.
        /// </summary>
        /// <param name="accessPackageResourceRoleScopeToUpdate">The AccessPackageResourceRoleScope 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 AccessPackageResourceRoleScope.</returns>
        public async System.Threading.Tasks.Task <AccessPackageResourceRoleScope> UpdateAsync(AccessPackageResourceRoleScope accessPackageResourceRoleScopeToUpdate, CancellationToken cancellationToken)
        {
            if (accessPackageResourceRoleScopeToUpdate.AdditionalData != null)
            {
                if (accessPackageResourceRoleScopeToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
                    accessPackageResourceRoleScopeToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
                {
                    throw new ClientException(
                              new Error
                    {
                        Code    = GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, accessPackageResourceRoleScopeToUpdate.GetType().Name)
                    });
                }
            }
            if (accessPackageResourceRoleScopeToUpdate.AdditionalData != null)
            {
                if (accessPackageResourceRoleScopeToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
                    accessPackageResourceRoleScopeToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
                {
                    throw new ClientException(
                              new Error
                    {
                        Code    = GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, accessPackageResourceRoleScopeToUpdate.GetType().Name)
                    });
                }
            }
            this.ContentType = "application/json";
            this.Method      = "PATCH";
            var updatedEntity = await this.SendAsync <AccessPackageResourceRoleScope>(accessPackageResourceRoleScopeToUpdate, cancellationToken).ConfigureAwait(false);

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