/// <summary>
 /// Adds the specified DeviceEnrollmentConfiguration to the collection via POST.
 /// </summary>
 /// <param name="deviceEnrollmentConfiguration">The DeviceEnrollmentConfiguration to add.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
 /// <returns>The created DeviceEnrollmentConfiguration.</returns>
 public System.Threading.Tasks.Task <DeviceEnrollmentConfiguration> AddAsync(DeviceEnrollmentConfiguration deviceEnrollmentConfiguration, CancellationToken cancellationToken)
 {
     this.ContentType = "application/json";
     this.Method      = "POST";
     deviceEnrollmentConfiguration.ODataType = string.Concat("#", StringHelper.ConvertTypeToLowerCamelCase(deviceEnrollmentConfiguration.GetType().FullName));
     return(this.SendAsync <DeviceEnrollmentConfiguration>(deviceEnrollmentConfiguration, cancellationToken));
 }
        /// <summary>
        /// Initializes any collection properties after deserialization, like next requests for paging.
        /// </summary>
        /// <param name="deviceEnrollmentConfigurationToInitialize">The <see cref="DeviceEnrollmentConfiguration"/> with the collection properties to initialize.</param>
        private void InitializeCollectionProperties(DeviceEnrollmentConfiguration deviceEnrollmentConfigurationToInitialize)
        {
            if (deviceEnrollmentConfigurationToInitialize != null && deviceEnrollmentConfigurationToInitialize.AdditionalData != null)
            {
                if (deviceEnrollmentConfigurationToInitialize.Assignments != null && deviceEnrollmentConfigurationToInitialize.Assignments.CurrentPage != null)
                {
                    deviceEnrollmentConfigurationToInitialize.Assignments.AdditionalData = deviceEnrollmentConfigurationToInitialize.AdditionalData;

                    object nextPageLink;
                    deviceEnrollmentConfigurationToInitialize.AdditionalData.TryGetValue("*****@*****.**", out nextPageLink);
                    var nextPageLinkString = nextPageLink as string;

                    if (!string.IsNullOrEmpty(nextPageLinkString))
                    {
                        deviceEnrollmentConfigurationToInitialize.Assignments.InitializeNextPageRequest(
                            this.Client,
                            nextPageLinkString);
                    }
                }
            }
        }
 /// <summary>
 /// Adds the specified DeviceEnrollmentConfiguration to the collection via POST.
 /// </summary>
 /// <param name="deviceEnrollmentConfiguration">The DeviceEnrollmentConfiguration to add.</param>
 /// <returns>The created DeviceEnrollmentConfiguration.</returns>
 public System.Threading.Tasks.Task <DeviceEnrollmentConfiguration> AddAsync(DeviceEnrollmentConfiguration deviceEnrollmentConfiguration)
 {
     return(this.AddAsync(deviceEnrollmentConfiguration, CancellationToken.None));
 }
        /// <summary>
        /// Creates the specified DeviceEnrollmentConfiguration using POST.
        /// </summary>
        /// <param name="deviceEnrollmentConfigurationToCreate">The DeviceEnrollmentConfiguration to create.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>The created DeviceEnrollmentConfiguration.</returns>
        public async System.Threading.Tasks.Task <DeviceEnrollmentConfiguration> CreateAsync(DeviceEnrollmentConfiguration deviceEnrollmentConfigurationToCreate, CancellationToken cancellationToken)
        {
            this.ContentType = "application/json";
            this.Method      = "POST";
            var newEntity = await this.SendAsync <DeviceEnrollmentConfiguration>(deviceEnrollmentConfigurationToCreate, cancellationToken).ConfigureAwait(false);

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

            this.InitializeCollectionProperties(updatedEntity);
            return(updatedEntity);
        }
 /// <summary>
 /// Updates the specified DeviceEnrollmentConfiguration using PATCH.
 /// </summary>
 /// <param name="deviceEnrollmentConfigurationToUpdate">The DeviceEnrollmentConfiguration to update.</param>
 /// <returns>The updated DeviceEnrollmentConfiguration.</returns>
 public System.Threading.Tasks.Task <DeviceEnrollmentConfiguration> UpdateAsync(DeviceEnrollmentConfiguration deviceEnrollmentConfigurationToUpdate)
 {
     return(this.UpdateAsync(deviceEnrollmentConfigurationToUpdate, CancellationToken.None));
 }