/src/Microsoft.Graph/Generated/requests/OrganizationRequest.cs
https://github.com/microsoftgraph/msgraph-sdk-dotnet · C# · 274 lines · 167 code · 27 blank · 80 comment · 28 complexity · 7987b2460144f6ddb8ea02390087dfac MD5 · raw file
- // ------------------------------------------------------------------------------
- // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
- // ------------------------------------------------------------------------------
- // **NOTE** This file was generated by a tool and any changes will be overwritten.
- // <auto-generated/>
- // Template Source: Templates\CSharp\Requests\EntityRequest.cs.tt
- namespace Microsoft.Graph
- {
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Net.Http;
- using System.Threading;
- using System.Linq.Expressions;
- /// <summary>
- /// The type OrganizationRequest.
- /// </summary>
- public partial class OrganizationRequest : BaseRequest, IOrganizationRequest
- {
- /// <summary>
- /// Constructs a new OrganizationRequest.
- /// </summary>
- /// <param name="requestUrl">The URL for the built request.</param>
- /// <param name="client">The <see cref="IBaseClient"/> for handling requests.</param>
- /// <param name="options">Query and header option name value pairs for the request.</param>
- public OrganizationRequest(
- string requestUrl,
- IBaseClient client,
- IEnumerable<Option> options)
- : base(requestUrl, client, options)
- {
- }
- /// <summary>
- /// Creates the specified Organization using POST.
- /// </summary>
- /// <param name="organizationToCreate">The Organization to create.</param>
- /// <returns>The created Organization.</returns>
- public System.Threading.Tasks.Task<Organization> CreateAsync(Organization organizationToCreate)
- {
- return this.CreateAsync(organizationToCreate, CancellationToken.None);
- }
- /// <summary>
- /// Creates the specified Organization using POST.
- /// </summary>
- /// <param name="organizationToCreate">The Organization to create.</param>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
- /// <returns>The created Organization.</returns>
- public async System.Threading.Tasks.Task<Organization> CreateAsync(Organization organizationToCreate, CancellationToken cancellationToken)
- {
- this.ContentType = "application/json";
- this.Method = "POST";
- var newEntity = await this.SendAsync<Organization>(organizationToCreate, cancellationToken).ConfigureAwait(false);
- this.InitializeCollectionProperties(newEntity);
- return newEntity;
- }
- /// <summary>
- /// Deletes the specified Organization.
- /// </summary>
- /// <returns>The task to await.</returns>
- public System.Threading.Tasks.Task DeleteAsync()
- {
- return this.DeleteAsync(CancellationToken.None);
- }
- /// <summary>
- /// Deletes the specified Organization.
- /// </summary>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
- /// <returns>The task to await.</returns>
- public async System.Threading.Tasks.Task DeleteAsync(CancellationToken cancellationToken)
- {
- this.Method = "DELETE";
- await this.SendAsync<Organization>(null, cancellationToken).ConfigureAwait(false);
- }
- /// <summary>
- /// Gets the specified Organization.
- /// </summary>
- /// <returns>The Organization.</returns>
- public System.Threading.Tasks.Task<Organization> GetAsync()
- {
- return this.GetAsync(CancellationToken.None);
- }
- /// <summary>
- /// Gets the specified Organization.
- /// </summary>
- /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
- /// <returns>The Organization.</returns>
- public async System.Threading.Tasks.Task<Organization> GetAsync(CancellationToken cancellationToken)
- {
- this.Method = "GET";
- var retrievedEntity = await this.SendAsync<Organization>(null, cancellationToken).ConfigureAwait(false);
- this.InitializeCollectionProperties(retrievedEntity);
- return retrievedEntity;
- }
- /// <summary>
- /// Updates the specified Organization using PATCH.
- /// </summary>
- /// <param name="organizationToUpdate">The Organization to update.</param>
- /// <returns>The updated Organization.</returns>
- public System.Threading.Tasks.Task<Organization> UpdateAsync(Organization organizationToUpdate)
- {
- return this.UpdateAsync(organizationToUpdate, CancellationToken.None);
- }
- /// <summary>
- /// Updates the specified Organization using PATCH.
- /// </summary>
- /// <param name="organizationToUpdate">The Organization 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 Organization.</returns>
- public async System.Threading.Tasks.Task<Organization> UpdateAsync(Organization organizationToUpdate, CancellationToken cancellationToken)
- {
- if (organizationToUpdate.AdditionalData != null)
- {
- if (organizationToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
- organizationToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
- {
- throw new ClientException(
- new Error
- {
- Code = GeneratedErrorConstants.Codes.NotAllowed,
- Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, organizationToUpdate.GetType().Name)
- });
- }
- }
- if (organizationToUpdate.AdditionalData != null)
- {
- if (organizationToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
- organizationToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
- {
- throw new ClientException(
- new Error
- {
- Code = GeneratedErrorConstants.Codes.NotAllowed,
- Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, organizationToUpdate.GetType().Name)
- });
- }
- }
- this.ContentType = "application/json";
- this.Method = "PATCH";
- var updatedEntity = await this.SendAsync<Organization>(organizationToUpdate, cancellationToken).ConfigureAwait(false);
- this.InitializeCollectionProperties(updatedEntity);
- return updatedEntity;
- }
- /// <summary>
- /// Adds the specified expand value to the request.
- /// </summary>
- /// <param name="value">The expand value.</param>
- /// <returns>The request object to send.</returns>
- public IOrganizationRequest Expand(string value)
- {
- this.QueryOptions.Add(new QueryOption("$expand", value));
- return this;
- }
- /// <summary>
- /// Adds the specified expand value to the request.
- /// </summary>
- /// <param name="expandExpression">The expression from which to calculate the expand value.</param>
- /// <returns>The request object to send.</returns>
- public IOrganizationRequest Expand(Expression<Func<Organization, object>> expandExpression)
- {
- if (expandExpression == null)
- {
- throw new ArgumentNullException(nameof(expandExpression));
- }
- string error;
- string value = ExpressionExtractHelper.ExtractMembers(expandExpression, out error);
- if (value == null)
- {
- throw new ArgumentException(error, nameof(expandExpression));
- }
- else
- {
- this.QueryOptions.Add(new QueryOption("$expand", value));
- }
- return this;
- }
- /// <summary>
- /// Adds the specified select value to the request.
- /// </summary>
- /// <param name="value">The select value.</param>
- /// <returns>The request object to send.</returns>
- public IOrganizationRequest Select(string value)
- {
- this.QueryOptions.Add(new QueryOption("$select", value));
- return this;
- }
- /// <summary>
- /// Adds the specified select value to the request.
- /// </summary>
- /// <param name="selectExpression">The expression from which to calculate the select value.</param>
- /// <returns>The request object to send.</returns>
- public IOrganizationRequest Select(Expression<Func<Organization, object>> selectExpression)
- {
- if (selectExpression == null)
- {
- throw new ArgumentNullException(nameof(selectExpression));
- }
- string error;
- string value = ExpressionExtractHelper.ExtractMembers(selectExpression, out error);
- if (value == null)
- {
- throw new ArgumentException(error, nameof(selectExpression));
- }
- else
- {
- this.QueryOptions.Add(new QueryOption("$select", value));
- }
- return this;
- }
- /// <summary>
- /// Initializes any collection properties after deserialization, like next requests for paging.
- /// </summary>
- /// <param name="organizationToInitialize">The <see cref="Organization"/> with the collection properties to initialize.</param>
- private void InitializeCollectionProperties(Organization organizationToInitialize)
- {
- if (organizationToInitialize != null && organizationToInitialize.AdditionalData != null)
- {
- if (organizationToInitialize.CertificateBasedAuthConfiguration != null && organizationToInitialize.CertificateBasedAuthConfiguration.CurrentPage != null)
- {
- organizationToInitialize.CertificateBasedAuthConfiguration.AdditionalData = organizationToInitialize.AdditionalData;
- object nextPageLink;
- organizationToInitialize.AdditionalData.TryGetValue("certificateBasedAuthConfiguration@odata.nextLink", out nextPageLink);
- var nextPageLinkString = nextPageLink as string;
- if (!string.IsNullOrEmpty(nextPageLinkString))
- {
- organizationToInitialize.CertificateBasedAuthConfiguration.InitializeNextPageRequest(
- this.Client,
- nextPageLinkString);
- }
- }
- if (organizationToInitialize.Extensions != null && organizationToInitialize.Extensions.CurrentPage != null)
- {
- organizationToInitialize.Extensions.AdditionalData = organizationToInitialize.AdditionalData;
- object nextPageLink;
- organizationToInitialize.AdditionalData.TryGetValue("extensions@odata.nextLink", out nextPageLink);
- var nextPageLinkString = nextPageLink as string;
- if (!string.IsNullOrEmpty(nextPageLinkString))
- {
- organizationToInitialize.Extensions.InitializeNextPageRequest(
- this.Client,
- nextPageLinkString);
- }
- }
- }
- }
- }
- }