/// <summary>
        /// Initializes any collection properties after deserialization, like next requests for paging.
        /// </summary>
        /// <param name="deviceManagementTemplateToInitialize">The <see cref="DeviceManagementTemplate"/> with the collection properties to initialize.</param>
        private void InitializeCollectionProperties(DeviceManagementTemplate deviceManagementTemplateToInitialize)
        {
            if (deviceManagementTemplateToInitialize != null && deviceManagementTemplateToInitialize.AdditionalData != null)
            {
                if (deviceManagementTemplateToInitialize.Settings != null && deviceManagementTemplateToInitialize.Settings.CurrentPage != null)
                {
                    deviceManagementTemplateToInitialize.Settings.AdditionalData = deviceManagementTemplateToInitialize.AdditionalData;

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

                    if (!string.IsNullOrEmpty(nextPageLinkString))
                    {
                        deviceManagementTemplateToInitialize.Settings.InitializeNextPageRequest(
                            this.Client,
                            nextPageLinkString);
                    }
                }

                if (deviceManagementTemplateToInitialize.Categories != null && deviceManagementTemplateToInitialize.Categories.CurrentPage != null)
                {
                    deviceManagementTemplateToInitialize.Categories.AdditionalData = deviceManagementTemplateToInitialize.AdditionalData;

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

                    if (!string.IsNullOrEmpty(nextPageLinkString))
                    {
                        deviceManagementTemplateToInitialize.Categories.InitializeNextPageRequest(
                            this.Client,
                            nextPageLinkString);
                    }
                }

                if (deviceManagementTemplateToInitialize.MigratableTo != null && deviceManagementTemplateToInitialize.MigratableTo.CurrentPage != null)
                {
                    deviceManagementTemplateToInitialize.MigratableTo.AdditionalData = deviceManagementTemplateToInitialize.AdditionalData;

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

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

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

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