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

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

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