/// <summary> /// Updates the specified GroupPolicyDefinition using PATCH. /// </summary> /// <param name="groupPolicyDefinitionToUpdate">The GroupPolicyDefinition 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 GroupPolicyDefinition.</returns> public async System.Threading.Tasks.Task <GroupPolicyDefinition> UpdateAsync(GroupPolicyDefinition groupPolicyDefinitionToUpdate, CancellationToken cancellationToken) { if (groupPolicyDefinitionToUpdate.AdditionalData != null) { if (groupPolicyDefinitionToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) || groupPolicyDefinitionToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode)) { throw new ClientException( new Error { Code = GeneratedErrorConstants.Codes.NotAllowed, Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, groupPolicyDefinitionToUpdate.GetType().Name) }); } } if (groupPolicyDefinitionToUpdate.AdditionalData != null) { if (groupPolicyDefinitionToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) || groupPolicyDefinitionToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode)) { throw new ClientException( new Error { Code = GeneratedErrorConstants.Codes.NotAllowed, Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, groupPolicyDefinitionToUpdate.GetType().Name) }); } } this.ContentType = "application/json"; this.Method = "PATCH"; var updatedEntity = await this.SendAsync <GroupPolicyDefinition>(groupPolicyDefinitionToUpdate, cancellationToken).ConfigureAwait(false); this.InitializeCollectionProperties(updatedEntity); return(updatedEntity); }
/// <summary> /// Creates the specified GroupPolicyDefinition using POST. /// </summary> /// <param name="groupPolicyDefinitionToCreate">The GroupPolicyDefinition to create.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>The created GroupPolicyDefinition.</returns> public async System.Threading.Tasks.Task <GroupPolicyDefinition> CreateAsync(GroupPolicyDefinition groupPolicyDefinitionToCreate, CancellationToken cancellationToken) { this.ContentType = "application/json"; this.Method = "POST"; var newEntity = await this.SendAsync <GroupPolicyDefinition>(groupPolicyDefinitionToCreate, cancellationToken).ConfigureAwait(false); return(newEntity); }
/// <summary> /// Adds the specified GroupPolicyDefinition to the collection via POST. /// </summary> /// <param name="groupPolicyDefinition">The GroupPolicyDefinition to add.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>The task to await.</returns> public System.Threading.Tasks.Task AddAsync(GroupPolicyDefinition groupPolicyDefinition, CancellationToken cancellationToken) { this.ContentType = "application/json"; this.Method = "POST"; if (string.IsNullOrEmpty(groupPolicyDefinition.Id)) { throw new ServiceException(new Error { Code = "invalidRequest", Message = "ID is required to add a reference." }); } var requestBody = new ReferenceRequestBody { ODataId = string.Format("{0}/deviceManagement/definitions/{1}", this.Client.BaseUrl, groupPolicyDefinition.Id) }; return(this.SendAsync(requestBody, cancellationToken)); }
/// <summary> /// Initializes any collection properties after deserialization, like next requests for paging. /// </summary> /// <param name="groupPolicyDefinitionToInitialize">The <see cref="GroupPolicyDefinition"/> with the collection properties to initialize.</param> private void InitializeCollectionProperties(GroupPolicyDefinition groupPolicyDefinitionToInitialize) { if (groupPolicyDefinitionToInitialize != null && groupPolicyDefinitionToInitialize.AdditionalData != null) { if (groupPolicyDefinitionToInitialize.Presentations != null && groupPolicyDefinitionToInitialize.Presentations.CurrentPage != null) { groupPolicyDefinitionToInitialize.Presentations.AdditionalData = groupPolicyDefinitionToInitialize.AdditionalData; object nextPageLink; groupPolicyDefinitionToInitialize.AdditionalData.TryGetValue("*****@*****.**", out nextPageLink); var nextPageLinkString = nextPageLink as string; if (!string.IsNullOrEmpty(nextPageLinkString)) { groupPolicyDefinitionToInitialize.Presentations.InitializeNextPageRequest( this.Client, nextPageLinkString); } } } }
/// <summary> /// Creates the specified GroupPolicyDefinition using POST. /// </summary> /// <param name="groupPolicyDefinitionToCreate">The GroupPolicyDefinition to create.</param> /// <returns>The created GroupPolicyDefinition.</returns> public System.Threading.Tasks.Task <GroupPolicyDefinition> CreateAsync(GroupPolicyDefinition groupPolicyDefinitionToCreate) { return(this.CreateAsync(groupPolicyDefinitionToCreate, CancellationToken.None)); }
/// <summary> /// Adds the specified GroupPolicyDefinition to the collection via POST. /// </summary> /// <param name="groupPolicyDefinition">The GroupPolicyDefinition to add.</param> /// <returns>The task to await.</returns> public System.Threading.Tasks.Task AddAsync(GroupPolicyDefinition groupPolicyDefinition) { return(this.AddAsync(groupPolicyDefinition, CancellationToken.None)); }
/// <summary> /// Adds the specified GroupPolicyDefinition to the collection via POST. /// </summary> /// <param name="groupPolicyDefinition">The GroupPolicyDefinition to add.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param> /// <returns>The created GroupPolicyDefinition.</returns> public System.Threading.Tasks.Task <GroupPolicyDefinition> AddAsync(GroupPolicyDefinition groupPolicyDefinition, CancellationToken cancellationToken) { this.ContentType = "application/json"; this.Method = "POST"; return(this.SendAsync <GroupPolicyDefinition>(groupPolicyDefinition, cancellationToken)); }