/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

  1. // ------------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
  3. // ------------------------------------------------------------------------------
  4. // **NOTE** This file was generated by a tool and any changes will be overwritten.
  5. // <auto-generated/>
  6. // Template Source: Templates\CSharp\Requests\EntityRequest.cs.tt
  7. namespace Microsoft.Graph
  8. {
  9. using System;
  10. using System.Collections.Generic;
  11. using System.IO;
  12. using System.Net.Http;
  13. using System.Threading;
  14. using System.Linq.Expressions;
  15. /// <summary>
  16. /// The type OrganizationRequest.
  17. /// </summary>
  18. public partial class OrganizationRequest : BaseRequest, IOrganizationRequest
  19. {
  20. /// <summary>
  21. /// Constructs a new OrganizationRequest.
  22. /// </summary>
  23. /// <param name="requestUrl">The URL for the built request.</param>
  24. /// <param name="client">The <see cref="IBaseClient"/> for handling requests.</param>
  25. /// <param name="options">Query and header option name value pairs for the request.</param>
  26. public OrganizationRequest(
  27. string requestUrl,
  28. IBaseClient client,
  29. IEnumerable<Option> options)
  30. : base(requestUrl, client, options)
  31. {
  32. }
  33. /// <summary>
  34. /// Creates the specified Organization using POST.
  35. /// </summary>
  36. /// <param name="organizationToCreate">The Organization to create.</param>
  37. /// <returns>The created Organization.</returns>
  38. public System.Threading.Tasks.Task<Organization> CreateAsync(Organization organizationToCreate)
  39. {
  40. return this.CreateAsync(organizationToCreate, CancellationToken.None);
  41. }
  42. /// <summary>
  43. /// Creates the specified Organization using POST.
  44. /// </summary>
  45. /// <param name="organizationToCreate">The Organization to create.</param>
  46. /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
  47. /// <returns>The created Organization.</returns>
  48. public async System.Threading.Tasks.Task<Organization> CreateAsync(Organization organizationToCreate, CancellationToken cancellationToken)
  49. {
  50. this.ContentType = "application/json";
  51. this.Method = "POST";
  52. var newEntity = await this.SendAsync<Organization>(organizationToCreate, cancellationToken).ConfigureAwait(false);
  53. this.InitializeCollectionProperties(newEntity);
  54. return newEntity;
  55. }
  56. /// <summary>
  57. /// Deletes the specified Organization.
  58. /// </summary>
  59. /// <returns>The task to await.</returns>
  60. public System.Threading.Tasks.Task DeleteAsync()
  61. {
  62. return this.DeleteAsync(CancellationToken.None);
  63. }
  64. /// <summary>
  65. /// Deletes the specified Organization.
  66. /// </summary>
  67. /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
  68. /// <returns>The task to await.</returns>
  69. public async System.Threading.Tasks.Task DeleteAsync(CancellationToken cancellationToken)
  70. {
  71. this.Method = "DELETE";
  72. await this.SendAsync<Organization>(null, cancellationToken).ConfigureAwait(false);
  73. }
  74. /// <summary>
  75. /// Gets the specified Organization.
  76. /// </summary>
  77. /// <returns>The Organization.</returns>
  78. public System.Threading.Tasks.Task<Organization> GetAsync()
  79. {
  80. return this.GetAsync(CancellationToken.None);
  81. }
  82. /// <summary>
  83. /// Gets the specified Organization.
  84. /// </summary>
  85. /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
  86. /// <returns>The Organization.</returns>
  87. public async System.Threading.Tasks.Task<Organization> GetAsync(CancellationToken cancellationToken)
  88. {
  89. this.Method = "GET";
  90. var retrievedEntity = await this.SendAsync<Organization>(null, cancellationToken).ConfigureAwait(false);
  91. this.InitializeCollectionProperties(retrievedEntity);
  92. return retrievedEntity;
  93. }
  94. /// <summary>
  95. /// Updates the specified Organization using PATCH.
  96. /// </summary>
  97. /// <param name="organizationToUpdate">The Organization to update.</param>
  98. /// <returns>The updated Organization.</returns>
  99. public System.Threading.Tasks.Task<Organization> UpdateAsync(Organization organizationToUpdate)
  100. {
  101. return this.UpdateAsync(organizationToUpdate, CancellationToken.None);
  102. }
  103. /// <summary>
  104. /// Updates the specified Organization using PATCH.
  105. /// </summary>
  106. /// <param name="organizationToUpdate">The Organization to update.</param>
  107. /// <param name="cancellationToken">The <see cref="CancellationToken"/> for the request.</param>
  108. /// <exception cref="ClientException">Thrown when an object returned in a response is used for updating an object in Microsoft Graph.</exception>
  109. /// <returns>The updated Organization.</returns>
  110. public async System.Threading.Tasks.Task<Organization> UpdateAsync(Organization organizationToUpdate, CancellationToken cancellationToken)
  111. {
  112. if (organizationToUpdate.AdditionalData != null)
  113. {
  114. if (organizationToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
  115. organizationToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
  116. {
  117. throw new ClientException(
  118. new Error
  119. {
  120. Code = GeneratedErrorConstants.Codes.NotAllowed,
  121. Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, organizationToUpdate.GetType().Name)
  122. });
  123. }
  124. }
  125. if (organizationToUpdate.AdditionalData != null)
  126. {
  127. if (organizationToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.ResponseHeaders) ||
  128. organizationToUpdate.AdditionalData.ContainsKey(Constants.HttpPropertyNames.StatusCode))
  129. {
  130. throw new ClientException(
  131. new Error
  132. {
  133. Code = GeneratedErrorConstants.Codes.NotAllowed,
  134. Message = String.Format(GeneratedErrorConstants.Messages.ResponseObjectUsedForUpdate, organizationToUpdate.GetType().Name)
  135. });
  136. }
  137. }
  138. this.ContentType = "application/json";
  139. this.Method = "PATCH";
  140. var updatedEntity = await this.SendAsync<Organization>(organizationToUpdate, cancellationToken).ConfigureAwait(false);
  141. this.InitializeCollectionProperties(updatedEntity);
  142. return updatedEntity;
  143. }
  144. /// <summary>
  145. /// Adds the specified expand value to the request.
  146. /// </summary>
  147. /// <param name="value">The expand value.</param>
  148. /// <returns>The request object to send.</returns>
  149. public IOrganizationRequest Expand(string value)
  150. {
  151. this.QueryOptions.Add(new QueryOption("$expand", value));
  152. return this;
  153. }
  154. /// <summary>
  155. /// Adds the specified expand value to the request.
  156. /// </summary>
  157. /// <param name="expandExpression">The expression from which to calculate the expand value.</param>
  158. /// <returns>The request object to send.</returns>
  159. public IOrganizationRequest Expand(Expression<Func<Organization, object>> expandExpression)
  160. {
  161. if (expandExpression == null)
  162. {
  163. throw new ArgumentNullException(nameof(expandExpression));
  164. }
  165. string error;
  166. string value = ExpressionExtractHelper.ExtractMembers(expandExpression, out error);
  167. if (value == null)
  168. {
  169. throw new ArgumentException(error, nameof(expandExpression));
  170. }
  171. else
  172. {
  173. this.QueryOptions.Add(new QueryOption("$expand", value));
  174. }
  175. return this;
  176. }
  177. /// <summary>
  178. /// Adds the specified select value to the request.
  179. /// </summary>
  180. /// <param name="value">The select value.</param>
  181. /// <returns>The request object to send.</returns>
  182. public IOrganizationRequest Select(string value)
  183. {
  184. this.QueryOptions.Add(new QueryOption("$select", value));
  185. return this;
  186. }
  187. /// <summary>
  188. /// Adds the specified select value to the request.
  189. /// </summary>
  190. /// <param name="selectExpression">The expression from which to calculate the select value.</param>
  191. /// <returns>The request object to send.</returns>
  192. public IOrganizationRequest Select(Expression<Func<Organization, object>> selectExpression)
  193. {
  194. if (selectExpression == null)
  195. {
  196. throw new ArgumentNullException(nameof(selectExpression));
  197. }
  198. string error;
  199. string value = ExpressionExtractHelper.ExtractMembers(selectExpression, out error);
  200. if (value == null)
  201. {
  202. throw new ArgumentException(error, nameof(selectExpression));
  203. }
  204. else
  205. {
  206. this.QueryOptions.Add(new QueryOption("$select", value));
  207. }
  208. return this;
  209. }
  210. /// <summary>
  211. /// Initializes any collection properties after deserialization, like next requests for paging.
  212. /// </summary>
  213. /// <param name="organizationToInitialize">The <see cref="Organization"/> with the collection properties to initialize.</param>
  214. private void InitializeCollectionProperties(Organization organizationToInitialize)
  215. {
  216. if (organizationToInitialize != null && organizationToInitialize.AdditionalData != null)
  217. {
  218. if (organizationToInitialize.CertificateBasedAuthConfiguration != null && organizationToInitialize.CertificateBasedAuthConfiguration.CurrentPage != null)
  219. {
  220. organizationToInitialize.CertificateBasedAuthConfiguration.AdditionalData = organizationToInitialize.AdditionalData;
  221. object nextPageLink;
  222. organizationToInitialize.AdditionalData.TryGetValue("certificateBasedAuthConfiguration@odata.nextLink", out nextPageLink);
  223. var nextPageLinkString = nextPageLink as string;
  224. if (!string.IsNullOrEmpty(nextPageLinkString))
  225. {
  226. organizationToInitialize.CertificateBasedAuthConfiguration.InitializeNextPageRequest(
  227. this.Client,
  228. nextPageLinkString);
  229. }
  230. }
  231. if (organizationToInitialize.Extensions != null && organizationToInitialize.Extensions.CurrentPage != null)
  232. {
  233. organizationToInitialize.Extensions.AdditionalData = organizationToInitialize.AdditionalData;
  234. object nextPageLink;
  235. organizationToInitialize.AdditionalData.TryGetValue("extensions@odata.nextLink", out nextPageLink);
  236. var nextPageLinkString = nextPageLink as string;
  237. if (!string.IsNullOrEmpty(nextPageLinkString))
  238. {
  239. organizationToInitialize.Extensions.InitializeNextPageRequest(
  240. this.Client,
  241. nextPageLinkString);
  242. }
  243. }
  244. }
  245. }
  246. }
  247. }