/// <summary>
        /// Updates the specified LegalHold using PATCH.
        /// </summary>
        /// <param name="legalHoldToUpdate">The LegalHold 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 LegalHold.</returns>
        public async System.Threading.Tasks.Task <LegalHold> UpdateAsync(LegalHold legalHoldToUpdate, CancellationToken cancellationToken)
        {
            if (legalHoldToUpdate.AdditionalData != null)
            {
                if (legalHoldToUpdate.AdditionalData.ContainsKey(Microsoft.Graph.Constants.HttpPropertyNames.ResponseHeaders) ||
                    legalHoldToUpdate.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, legalHoldToUpdate.GetType().Name)
                    });
                }
            }
            if (legalHoldToUpdate.AdditionalData != null)
            {
                if (legalHoldToUpdate.AdditionalData.ContainsKey(Microsoft.Graph.Constants.HttpPropertyNames.ResponseHeaders) ||
                    legalHoldToUpdate.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, legalHoldToUpdate.GetType().Name)
                    });
                }
            }
            this.ContentType = "application/json";
            this.Method      = "PATCH";
            var updatedEntity = await this.SendAsync <LegalHold>(legalHoldToUpdate, cancellationToken).ConfigureAwait(false);

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

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

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

                    if (!string.IsNullOrEmpty(nextPageLinkString))
                    {
                        legalHoldToInitialize.SiteSources.InitializeNextPageRequest(
                            this.Client,
                            nextPageLinkString);
                    }
                }

                if (legalHoldToInitialize.UnifiedGroupSources != null && legalHoldToInitialize.UnifiedGroupSources.CurrentPage != null)
                {
                    legalHoldToInitialize.UnifiedGroupSources.AdditionalData = legalHoldToInitialize.AdditionalData;

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

                    if (!string.IsNullOrEmpty(nextPageLinkString))
                    {
                        legalHoldToInitialize.UnifiedGroupSources.InitializeNextPageRequest(
                            this.Client,
                            nextPageLinkString);
                    }
                }

                if (legalHoldToInitialize.UserSources != null && legalHoldToInitialize.UserSources.CurrentPage != null)
                {
                    legalHoldToInitialize.UserSources.AdditionalData = legalHoldToInitialize.AdditionalData;

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

                    if (!string.IsNullOrEmpty(nextPageLinkString))
                    {
                        legalHoldToInitialize.UserSources.InitializeNextPageRequest(
                            this.Client,
                            nextPageLinkString);
                    }
                }
            }
        }
 /// <summary>
 /// Creates the specified LegalHold using POST.
 /// </summary>
 /// <param name="legalHoldToCreate">The LegalHold to create.</param>
 /// <returns>The created LegalHold.</returns>
 public System.Threading.Tasks.Task <LegalHold> CreateAsync(LegalHold legalHoldToCreate)
 {
     return(this.CreateAsync(legalHoldToCreate, CancellationToken.None));
 }
 /// <summary>
 /// Adds the specified LegalHold to the collection via POST.
 /// </summary>
 /// <param name="legalHold">The LegalHold to add.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
 /// <returns>The created LegalHold.</returns>
 public System.Threading.Tasks.Task <LegalHold> AddAsync(LegalHold legalHold, CancellationToken cancellationToken)
 {
     this.ContentType = "application/json";
     this.Method      = "POST";
     return(this.SendAsync <LegalHold>(legalHold, cancellationToken));
 }
 /// <summary>
 /// Adds the specified LegalHold to the collection via POST.
 /// </summary>
 /// <param name="legalHold">The LegalHold to add.</param>
 /// <returns>The created LegalHold.</returns>
 public System.Threading.Tasks.Task <LegalHold> AddAsync(LegalHold legalHold)
 {
     return(this.AddAsync(legalHold, CancellationToken.None));
 }