Skip to content

Commit df56e7b

Browse files
committed
Adds prefer header to requests
1 parent 157790c commit df56e7b

15 files changed

+249
-193
lines changed

Graph-ASPNET-46-Snippets/Microsoft Graph ASPNET Snippets/Controllers/AccountController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public void SignOut()
3232
HttpContext.GetOwinContext().Authentication.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationType, CookieAuthenticationDefaults.AuthenticationType);
3333
}
3434

35-
3635
// Send an OpenID Connect sign-out request.
3736
HttpContext.GetOwinContext().Authentication.SignOut(
3837
CookieAuthenticationDefaults.AuthenticationType);

Graph-ASPNET-46-Snippets/Microsoft Graph ASPNET Snippets/Controllers/EventsController.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ namespace Microsoft_Graph_ASPNET_Snippets.Controllers
1717
[Authorize]
1818
public class EventsController : Controller
1919
{
20-
// Initialize the GraphServiceClient.
21-
GraphServiceClient graphClient;
2220
EventsService eventsService;
2321

2422
public EventsController()
2523
{
2624
// Initialize the GraphServiceClient.
27-
graphClient = SDKHelper.GetAuthenticatedClient();
28-
eventsService = new EventsService();
25+
GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
26+
eventsService = new EventsService(graphClient);
2927
}
3028
public ActionResult Index()
3129
{
@@ -39,7 +37,7 @@ public async Task<ActionResult> GetMyEvents()
3937
try
4038
{
4139
// Get events.
42-
results.Items = await eventsService.GetMyEvents(graphClient);
40+
results.Items = await eventsService.GetMyEvents();
4341
}
4442
catch (ServiceException se)
4543
{
@@ -60,7 +58,7 @@ public async Task<ActionResult> GetMyCalendarView()
6058
try
6159
{
6260
// Get a calendar view.
63-
results.Items = await eventsService.GetMyCalendarView(graphClient);
61+
results.Items = await eventsService.GetMyCalendarView();
6462
}
6563
catch (ServiceException se)
6664
{
@@ -82,7 +80,7 @@ public async Task<ActionResult> CreateEvent()
8280
try
8381
{
8482
// Create the event.
85-
results.Items = await eventsService.CreateEvent(graphClient);
83+
results.Items = await eventsService.CreateEvent();
8684
}
8785
catch (ServiceException se)
8886
{
@@ -103,7 +101,7 @@ public async Task<ActionResult> GetEvent(string id)
103101
try
104102
{
105103
// Get the event.
106-
results.Items = await eventsService.GetEvent(graphClient, id);
104+
results.Items = await eventsService.GetEvent(id);
107105
}
108106
catch (ServiceException se)
109107
{
@@ -125,7 +123,7 @@ public async Task<ActionResult> UpdateEvent(string id, string name)
125123
try
126124
{
127125
// Update the event.
128-
results.Items = await eventsService.UpdateEvent(graphClient, id, name);
126+
results.Items = await eventsService.UpdateEvent(id, name);
129127
}
130128
catch (ServiceException se)
131129
{
@@ -146,7 +144,7 @@ public async Task<ActionResult> DeleteEvent(string id)
146144
try
147145
{
148146
// Delete the event.
149-
results.Items = await eventsService.DeleteEvent(graphClient, id);
147+
results.Items = await eventsService.DeleteEvent(id);
150148
}
151149
catch (ServiceException se)
152150
{
@@ -169,7 +167,7 @@ public async Task<ActionResult> AcceptMeetingRequest(string id)
169167
try
170168
{
171169
// Accept the meeting.
172-
results.Items = await eventsService.AcceptMeetingRequest(graphClient, id);
170+
results.Items = await eventsService.AcceptMeetingRequest(id);
173171
}
174172
catch (ServiceException se)
175173
{

Graph-ASPNET-46-Snippets/Microsoft Graph ASPNET Snippets/Controllers/ExtensionsController.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ namespace Microsoft_Graph_ASPNET_Snippets.Controllers
1313
[Authorize]
1414
public class ExtensionsController : Controller
1515
{
16-
GraphServiceClient graphClient;
1716
ExtensionsService extensionsService;
1817
public ExtensionsController()
1918
{
20-
graphClient = SDKHelper.GetAuthenticatedClient();
21-
extensionsService = new ExtensionsService();
19+
GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
20+
extensionsService = new ExtensionsService(graphClient);
2221
}
2322

2423
// Open extensions sample built around https://developer.microsoft.com/en-us/graph/docs/concepts/extensibility_open_users
@@ -33,8 +32,7 @@ public async Task<ActionResult> AddOpenExtensionToMe()
3332
ResultsViewModel results = new ResultsViewModel();
3433
try
3534
{
36-
results.Items = await extensionsService.AddOpenExtensionToMe(graphClient,
37-
extensionName,
35+
results.Items = await extensionsService.AddOpenExtensionToMe(extensionName,
3836
new Dictionary<string, object>()
3937
{ {"theme", "dark"}, {"color","purple"}, {"lang","Japanese"}});
4038
}
@@ -56,7 +54,7 @@ public async Task<ActionResult> GetOpenExtensionsForMe()
5654
ResultsViewModel results = new ResultsViewModel();
5755
try
5856
{
59-
results.Items = await extensionsService.GetOpenExtensionsForMe(graphClient);
57+
results.Items = await extensionsService.GetOpenExtensionsForMe();
6058
}
6159
catch (ServiceException se)
6260
{
@@ -77,8 +75,7 @@ public async Task<ActionResult> UpdateOpenExtensionForMe()
7775
try
7876
{
7977
// For updating a single dictionary item, you would first need to retrieve & then update the extension
80-
await extensionsService.UpdateOpenExtensionForMe(graphClient,
81-
extensionName,
78+
await extensionsService.UpdateOpenExtensionForMe(extensionName,
8279
new Dictionary<string, object>()
8380
{ {"theme", "light"}, {"color","yellow"}, {"lang","Swahili"}});
8481

@@ -102,7 +99,7 @@ public async Task<ActionResult> DeleteOpenExtensionForMe()
10299
ResultsViewModel results = new ResultsViewModel();
103100
try
104101
{
105-
await extensionsService.DeleteOpenExtensionForMe(graphClient, extensionName);
102+
await extensionsService.DeleteOpenExtensionForMe(extensionName);
106103

107104
results.Items = new List<ResultsItem>() { new ResultsItem() { Display = $"{extensionName} {Resource.Extensions_deleted}" } };
108105
}

Graph-ASPNET-46-Snippets/Microsoft Graph ASPNET Snippets/Controllers/FilesController.cs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ namespace Microsoft_Graph_ASPNET_Snippets.Controllers
1818
[Authorize]
1919
public class FilesController : Controller
2020
{
21-
GraphServiceClient graphClient;
2221
FilesService filesService;
2322
public FilesController()
2423
{
25-
graphClient = SDKHelper.GetAuthenticatedClient();
26-
filesService = new FilesService();
24+
GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
25+
filesService = new FilesService(graphClient);
2726
}
2827

2928
public ActionResult Index()
@@ -38,7 +37,7 @@ public async Task<ActionResult> GetMyFilesAndFolders()
3837
try
3938
{
4039
// Get the files and folders in the current user's drive.
41-
results.Items = await filesService.GetMyFilesAndFolders(graphClient);
40+
results.Items = await filesService.GetMyFilesAndFolders();
4241
}
4342
catch (ServiceException se)
4443
{
@@ -59,7 +58,7 @@ public async Task<ActionResult> GetSharedWithMe()
5958
try
6059
{
6160
// Get the shared items.
62-
results.Items = await filesService.GetSharedWithMe(graphClient);
61+
results.Items = await filesService.GetSharedWithMe();
6362
}
6463
catch (ServiceException se)
6564
{
@@ -80,7 +79,7 @@ public async Task<ActionResult> GetMyDrive()
8079
try
8180
{
8281
// Get the current user's default drive.
83-
results.Items = await filesService.GetMyDrive(graphClient);
82+
results.Items = await filesService.GetMyDrive();
8483
}
8584
catch (ServiceException se)
8685
{
@@ -102,7 +101,7 @@ public async Task<ActionResult> CreateFile()
102101
try
103102
{
104103
// Add the file.
105-
results.Items = await filesService.CreateFile(graphClient);
104+
results.Items = await filesService.CreateFile();
106105
}
107106
catch (ServiceException se)
108107
{
@@ -123,7 +122,7 @@ public async Task<ActionResult> CreateFolder()
123122
try
124123
{
125124
// Add the folder.
126-
results.Items = await filesService.CreateFolder(graphClient);
125+
results.Items = await filesService.CreateFolder();
127126
}
128127
catch (ServiceException se)
129128
{
@@ -145,7 +144,7 @@ public async Task<ActionResult> UploadLargeFile()
145144
try
146145
{
147146
// Add the file.
148-
results.Items = await filesService.UploadLargeFile(graphClient);
147+
results.Items = await filesService.UploadLargeFile();
149148
}
150149
catch (ServiceException se)
151150
{
@@ -166,7 +165,7 @@ public async Task<ActionResult> GetFileOrFolderMetadata(string id)
166165
try
167166
{
168167
// Get the file or folder object.
169-
results.Items = await filesService.GetFileOrFolderMetadata(graphClient, id);
168+
results.Items = await filesService.GetFileOrFolderMetadata(id);
170169
}
171170
catch (ServiceException se)
172171
{
@@ -188,7 +187,7 @@ public async Task<ActionResult> DownloadFile(string id)
188187
try
189188
{
190189
// Download the file.
191-
results.Items = await filesService.DownloadFile(graphClient, id);
190+
results.Items = await filesService.DownloadFile(id);
192191

193192
// Handle selected item is not supported.
194193
foreach (var item in results.Items)
@@ -217,7 +216,7 @@ public async Task<ActionResult> UpdateFileOrFolderMetadata(string id, string nam
217216
try
218217
{
219218
// Update the item.
220-
results.Items = await filesService.UpdateFileOrFolderMetadata(graphClient, id, name);
219+
results.Items = await filesService.UpdateFileOrFolderMetadata(id, name);
221220
}
222221
catch (ServiceException se)
223222
{
@@ -239,7 +238,7 @@ public async Task<ActionResult> UpdateFileContent(string id)
239238
try
240239
{
241240
// Get the file. Make sure it's a .txt file (for the purposes of this snippet).
242-
results.Items = await filesService.UpdateFileContent(graphClient, id);
241+
results.Items = await filesService.UpdateFileContent(id);
243242

244243
// Handle selected item is not supported.
245244
foreach (var item in results.Items)
@@ -266,7 +265,7 @@ public async Task<ActionResult> DeleteFileOrFolder(string id)
266265
try
267266
{
268267
// Delete the item.
269-
results.Items = await filesService.DeleteFileOrFolder(graphClient, id);
268+
results.Items = await filesService.DeleteFileOrFolder(id);
270269
}
271270
catch (ServiceException se)
272271
{
@@ -286,7 +285,7 @@ public async Task<ActionResult> GetSharingLink(string id)
286285
ResultsViewModel results = new ResultsViewModel(false);
287286
try
288287
{
289-
results.Items = await filesService.GetSharingLink(graphClient, id);
288+
results.Items = await filesService.GetSharingLink(id);
290289
}
291290
catch (ServiceException se)
292291
{

Graph-ASPNET-46-Snippets/Microsoft Graph ASPNET Snippets/Controllers/GroupsController.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@ namespace Microsoft_Graph_ASPNET_Snippets.Controllers.Groups
1717
[Authorize]
1818
public class GroupsController : Controller
1919
{
20-
GraphServiceClient graphClient;
2120
GroupsService groupsService;
2221
public GroupsController()
2322
{
24-
graphClient = SDKHelper.GetAuthenticatedClient();
25-
groupsService = new GroupsService();
23+
GraphServiceClient graphClient = SDKHelper.GetAuthenticatedClient();
24+
groupsService = new GroupsService(graphClient);
2625
}
2726

2827
public ActionResult Index()
@@ -38,7 +37,7 @@ public async Task<ActionResult> GetGroups()
3837
try
3938
{
4039
// Get groups.
41-
results.Items = await groupsService.GetGroups(graphClient);
40+
results.Items = await groupsService.GetGroups();
4241
}
4342
catch (ServiceException se)
4443
{
@@ -60,7 +59,7 @@ public async Task<ActionResult> GetUnifiedGroups()
6059
try
6160
{
6261
// Get unified groups.
63-
results.Items = await groupsService.GetUnifiedGroups(graphClient);
62+
results.Items = await groupsService.GetUnifiedGroups();
6463
}
6564
catch (ServiceException se)
6665
{
@@ -82,7 +81,7 @@ public async Task<ActionResult> GetMyMemberOfGroups()
8281
try
8382
{
8483
// Get groups the current user is a direct member of.
85-
results.Items = await groupsService.GetMyMemberOfGroups(graphClient);
84+
results.Items = await groupsService.GetMyMemberOfGroups();
8685
}
8786
catch (ServiceException se)
8887
{
@@ -105,7 +104,7 @@ public async Task<ActionResult> CreateGroup()
105104
try
106105
{
107106
// Add the group.
108-
results.Items = await groupsService.CreateGroup(graphClient);
107+
results.Items = await groupsService.CreateGroup();
109108
}
110109
catch (ServiceException se)
111110
{
@@ -127,7 +126,7 @@ public async Task<ActionResult> GetGroup(string id)
127126
try
128127
{
129128
// Get the group.
130-
results.Items = await groupsService.GetGroup(graphClient, id);
129+
results.Items = await groupsService.GetGroup(id);
131130
}
132131
catch (ServiceException se)
133132
{
@@ -149,7 +148,7 @@ public async Task<ActionResult> GetMembers(string id)
149148
try
150149
{
151150
// Get group members.
152-
results.Items = await groupsService.GetMembers(graphClient, id);
151+
results.Items = await groupsService.GetMembers(id);
153152
}
154153
catch (ServiceException se)
155154
{
@@ -171,7 +170,7 @@ public async Task<ActionResult> GetOwners(string id)
171170
try
172171
{
173172
// Get group owners.
174-
results.Items = await groupsService.GetOwners(graphClient, id);
173+
results.Items = await groupsService.GetOwners(id);
175174
}
176175
catch (ServiceException se)
177176
{
@@ -194,7 +193,7 @@ public async Task<ActionResult> UpdateGroup(string id, string name)
194193
try
195194
{
196195
// Update the group.
197-
results.Items = await groupsService.UpdateGroup(graphClient, id, name);
196+
results.Items = await groupsService.UpdateGroup(id, name);
198197
}
199198
catch (ServiceException se)
200199
{
@@ -216,7 +215,7 @@ public async Task<ActionResult> DeleteGroup(string id)
216215
try
217216
{
218217
// Delete the group.
219-
results.Items = await groupsService.DeleteGroup(graphClient, id);
218+
results.Items = await groupsService.DeleteGroup(id);
220219
}
221220
catch (ServiceException se)
222221
{

0 commit comments

Comments
 (0)