Skip to content

Commit ae8abf2

Browse files
committed
New signature: graphClient.Me.Manager.Reference.Request().PutAsync(managerDirObj.Id); These changes affect I/DirectoryObjectReferenceRequest.cs and I/UserReferenceRequest.cs in the .Net Graph API. No current impacts for I/UserReferenceRequest since this is used in references to read-only properties (createdBy, lastModifiedBy). In fact, the changes shouldn't actually affect UserReferenceRequest with proper annotations. I/DirectoryObjectReferenceRequest.cs changes affect many scenarios. See all references to DirectoryObjectWithReferenceRequestBuilder. Tests in .Net Graph SDK: /Requests/Functional/UsersTests.cs/UserUpdateManager
1 parent e040521 commit ae8abf2

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed

Templates/CSharp/Base/EntityRequest.Base.template.tt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,71 @@ public string GetEntityDeleteAsyncMethod(OdcmClass odcmClass)
100100
return this.GetDeleteAsyncMethod(entityName, entityName);
101101
}
102102

103+
public void AppendPutRefenceAsyncHeader(string putTargetString, StringBuilder stringBuilder, bool includeSendParams)
104+
{
105+
if (includeSendParams)
106+
{
107+
stringBuilder.AppendFormat(" ");
108+
}
109+
110+
stringBuilder.Append("/// <summary>");
111+
stringBuilder.Append(Environment.NewLine);
112+
stringBuilder.AppendFormat(" /// Puts the specified {0} reference.", putTargetString);
113+
stringBuilder.Append(Environment.NewLine);
114+
stringBuilder.Append(" /// </summary>");
115+
stringBuilder.Append(Environment.NewLine);
116+
stringBuilder.AppendFormat(" /// <param name=\"id\">The {0} reference to update.</param>", putTargetString);
117+
118+
if (includeSendParams)
119+
{
120+
stringBuilder.Append(Environment.NewLine);
121+
stringBuilder.Append(" /// <param name=\"cancellationToken\">The <see cref=\"CancellationToken\"/> for the request.</param>");
122+
}
123+
124+
stringBuilder.Append(Environment.NewLine);
125+
stringBuilder.Append(" /// <returns>The task to await.</returns>");
126+
}
127+
128+
public string GetEntityReferencePutAsyncMethod(OdcmClass odcmClass)
129+
{
130+
var entityName = this.GetEntityNameString(odcmClass);
131+
132+
var stringBuilder = new StringBuilder();
133+
134+
this.AppendPutRefenceAsyncHeader(entityName, stringBuilder, false);
135+
stringBuilder.Append(Environment.NewLine);
136+
stringBuilder.Append(" public System.Threading.Tasks.Task PutAsync(string id)");
137+
stringBuilder.Append(@"
138+
{
139+
return this.PutAsync(id, CancellationToken.None);
140+
}");
141+
stringBuilder.Append(Environment.NewLine);
142+
stringBuilder.Append(Environment.NewLine);
143+
144+
this.AppendPutRefenceAsyncHeader(entityName, stringBuilder, true);
145+
stringBuilder.Append(Environment.NewLine);
146+
stringBuilder.Append(" public async System.Threading.Tasks.Task PutAsync(string id, CancellationToken cancellationToken)");
147+
stringBuilder.Append(@"
148+
{
149+
var baseUrl = this.Client.BaseUrl;");
150+
stringBuilder.Append(Environment.NewLine);
151+
stringBuilder.Append(@" var objectUri = string.Format(@""{0}/users/{1}"", baseUrl, id);");
152+
stringBuilder.Append(Environment.NewLine);
153+
stringBuilder.Append(@" var payload = new Newtonsoft.Json.Linq.JObject(");
154+
stringBuilder.Append(Environment.NewLine);
155+
stringBuilder.Append(@" new Newtonsoft.Json.Linq.JProperty(""@odata.id"", objectUri));");
156+
stringBuilder.Append(Environment.NewLine);
157+
stringBuilder.Append(@" this.Method = ""PUT"";");
158+
stringBuilder.Append(Environment.NewLine);
159+
stringBuilder.Append(@" this.ContentType = ""application/json"";");
160+
stringBuilder.Append(Environment.NewLine);
161+
stringBuilder.AppendFormat(" await this.SendAsync(payload.ToString(), cancellationToken).ConfigureAwait(false);");
162+
stringBuilder.Append(Environment.NewLine);
163+
stringBuilder.Append(" }");
164+
165+
return stringBuilder.ToString();
166+
}
167+
103168
public void AppendCreateAsyncHeader(string entityName, string lowerCaseEntityName, StringBuilder stringBuilder, bool includeSendParams)
104169
{
105170
if (includeSendParams)

Templates/CSharp/Base/IEntityRequest.Base.template.tt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public string GetEntityReferenceDeleteAsyncMethod(OdcmClass odcmClass)
2121
return this.GetDeleteAsyncMethod(string.Concat(this.GetEntityNameString(odcmClass), " reference"));
2222
}
2323

24+
public string GetEntityReferencePutAsyncMethod(OdcmClass odcmClass)
25+
{
26+
return this.GetPutAsyncMethod(string.Concat(this.GetEntityNameString(odcmClass), " reference"));
27+
}
2428

2529
// -------------------------------------------------------------
2630
// Methods for standard entity requests
@@ -118,6 +122,47 @@ public string GetDeleteAsyncMethod(string deleteTargetString)
118122
return stringBuilder.ToString();
119123
}
120124

125+
public void AppendPutAsyncMethodHeader(string putTargetString, StringBuilder stringBuilder, bool includeSendParams)
126+
{
127+
if (includeSendParams)
128+
{
129+
stringBuilder.Append(" ");
130+
}
131+
132+
stringBuilder.Append("/// <summary>");
133+
stringBuilder.Append(Environment.NewLine);
134+
stringBuilder.AppendFormat(" /// Puts the specified {0}.", putTargetString);
135+
stringBuilder.Append(Environment.NewLine);
136+
stringBuilder.Append(" /// </summary>");
137+
138+
if (includeSendParams)
139+
{
140+
stringBuilder.Append(Environment.NewLine);
141+
stringBuilder.Append(" /// <param name=\"cancellationToken\">The <see cref=\"CancellationToken\"/> for the request.</param>");
142+
}
143+
144+
stringBuilder.Append(Environment.NewLine);
145+
stringBuilder.Append(" /// <returns>The task to await.</returns>");
146+
}
147+
148+
public string GetPutAsyncMethod(string putTargetString)
149+
{
150+
var stringBuilder = new StringBuilder();
151+
152+
this.AppendPutAsyncMethodHeader(putTargetString, stringBuilder, false);
153+
stringBuilder.Append(Environment.NewLine);
154+
stringBuilder.Append(" System.Threading.Tasks.Task PutAsync(string id);");
155+
156+
stringBuilder.Append(Environment.NewLine);
157+
stringBuilder.Append(Environment.NewLine);
158+
159+
this.AppendPutAsyncMethodHeader(putTargetString, stringBuilder, true);
160+
stringBuilder.Append(Environment.NewLine);
161+
stringBuilder.Append(" System.Threading.Tasks.Task PutAsync(string id, CancellationToken cancellationToken);");
162+
163+
return stringBuilder.ToString();
164+
}
165+
121166
public string GetEntityDeleteAsyncMethod(OdcmClass odcmClass)
122167
{
123168
return this.GetDeleteAsyncMethod(this.GetEntityNameString(odcmClass));

Templates/CSharp/Requests/EntityReferenceRequest.cs.tt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ namespace <#=this.GetNamespaceName(entity)#>
2222
<# if (features.CanDelete) { #>
2323

2424
<#=this.GetEntityReferenceDeleteAsyncMethod(entity)#>
25+
<# } #>
26+
<# if (features.CanUpdate) { #>
27+
28+
<#=this.GetEntityReferencePutAsyncMethod(entity)#>
2529
<# } #>
2630
}
2731
}

Templates/CSharp/Requests/IEntityReferenceRequest.cs.tt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ namespace <#=this.GetNamespaceName(entity)#>
1919
{
2020
<# if (features.CanDelete) { #>
2121
<#=this.GetEntityReferenceDeleteAsyncMethod(entity)#>
22+
<# } #>
23+
<# if (features.CanUpdate) { #>
24+
25+
<#=this.GetEntityReferencePutAsyncMethod(entity)#>
2226
<# } #>
2327
}
2428
}

0 commit comments

Comments
 (0)