/// <summary>
        /// Updates the specified External using PATCH.
        /// </summary>
        /// <param name="externalToUpdate">The External to update.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <exception cref="Microsoft.Graph.ClientException">Thrown when an object returned in a response is used for updating an object in Microsoft Graph.</exception>
        /// <returns>The updated External.</returns>
        public async System.Threading.Tasks.Task <External> UpdateAsync(External externalToUpdate, CancellationToken cancellationToken)
        {
            if (externalToUpdate.AdditionalData != null)
            {
                if (externalToUpdate.AdditionalData.ContainsKey(Microsoft.Graph.Constants.HttpPropertyNames.ResponseHeaders) ||
                    externalToUpdate.AdditionalData.ContainsKey(Microsoft.Graph.Constants.HttpPropertyNames.StatusCode))
                {
                    throw new Microsoft.Graph.ClientException(
                              new Microsoft.Graph.Error
                    {
                        Code    = Microsoft.Graph.GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(Microsoft.Graph.GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, externalToUpdate.GetType().Name)
                    });
                }
            }
            if (externalToUpdate.AdditionalData != null)
            {
                if (externalToUpdate.AdditionalData.ContainsKey(Microsoft.Graph.Constants.HttpPropertyNames.ResponseHeaders) ||
                    externalToUpdate.AdditionalData.ContainsKey(Microsoft.Graph.Constants.HttpPropertyNames.StatusCode))
                {
                    throw new Microsoft.Graph.ClientException(
                              new Microsoft.Graph.Error
                    {
                        Code    = Microsoft.Graph.GeneratedErrorConstants.Codes.NotAllowed,
                        Message = String.Format(Microsoft.Graph.GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, externalToUpdate.GetType().Name)
                    });
                }
            }
            this.ContentType = "application/json";
            this.Method      = "PATCH";
            var updatedEntity = await this.SendAsync <External>(externalToUpdate, cancellationToken).ConfigureAwait(false);

            this.InitializeCollectionProperties(updatedEntity);
            return(updatedEntity);
        }
        /// <summary>
        /// Creates the specified External using POST.
        /// </summary>
        /// <param name="externalToCreate">The External to create.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
        /// <returns>The created External.</returns>
        public async System.Threading.Tasks.Task <External> CreateAsync(External externalToCreate, CancellationToken cancellationToken)
        {
            this.ContentType = "application/json";
            this.Method      = "POST";
            var newEntity = await this.SendAsync <External>(externalToCreate, cancellationToken).ConfigureAwait(false);

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

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

                    if (!string.IsNullOrEmpty(nextPageLinkString))
                    {
                        externalToInitialize.Connections.InitializeNextPageRequest(
                            this.Client,
                            nextPageLinkString);
                    }
                }
            }
        }
 /// <summary>
 /// Creates the specified External using POST.
 /// </summary>
 /// <param name="externalToCreate">The External to create.</param>
 /// <returns>The created External.</returns>
 public System.Threading.Tasks.Task <External> CreateAsync(External externalToCreate)
 {
     return(this.CreateAsync(externalToCreate, CancellationToken.None));
 }