Skip to content

Instantly share code, notes, and snippets.

View maisarissi's full-sized avatar

Maísa Rissi maisarissi

  • São Paulo, Brazil
  • 13:45 (UTC -03:00)
View GitHub Profile
@maisarissi
maisarissi / ODataCastSimplified.cs
Last active December 7, 2023 19:42
msgraph-dotnet-v5-ga-odata-cast
//Fetching the members of a group who are of the type User
var usersInGroup = await graphServiceClient
    .Groups["group-id"]
    .Members
    .GraphUser //cast to User
    .GetAsync();
List<User> userList = usersInGroup.Value;
//Similarly, members of the group of type ServicePrincipal
@maisarissi
maisarissi / Count.cs
Created February 8, 2023 20:27
msgraph-dotnet-v5-rc-count
var count = await graphServiceClient
    .Users
    .Count //Where applicable to enable the use of $count
    .GetAsync(requestConfiguration =>
        requestConfiguration.Headers.Add("ConsistencyLevel","eventual"));
@maisarissi
maisarissi / CustomAuthFlow.cs
Last active February 8, 2023 20:28
msgraph-dotnet-v5-rc-custom-auth-flow
public class TokenProvider : IAccessTokenProvider
{
public Task<string> GetAuthorizationTokenAsync(Uri uri,
Dictionary<string,
object> additionalAuthenticationContext = default,
CancellationToken cancellationToken = default)
{
var token = "token";
//get the token and return it in your own way
return Task.FromResult(token);
@maisarissi
maisarissi / ErrorHandling.cs
Last active February 8, 2023 20:28
msgraph-dotnet-v5-rc-error-handling
try
{
await graphServiceClient.Me.PatchAsync(user);
}
catch (ODataError odataError)
{
Console.WriteLine(odataError.Error.Code);
Console.WriteLine(odataError.Error.Message);
throw;
}
@maisarissi
maisarissi / Pagination.cs
Last active February 8, 2023 20:28
msgraph-dotnet-v5-rc-pagination
var usersResponse = await graphServiceClient
    .Users
    .GetAsync(requestConfiguration => {
        requestConfiguration.QueryParameters.Select = new string[] {"id", "createdDateTime"};
        requestConfiguration.QueryParameters.Top = 1; });
var userList = new List<User>();
var pageIterator = PageIterator<User,UserCollectionResponse>
    .CreatePageIterator(graphServiceClient,usersResponse, (user) => {
userList.Add(user);
@maisarissi
maisarissi / UserList.cs
Last active February 8, 2023 20:29
msgraph-dotnet-v5-rc-get-user-list
var usersResponse = await graphServiceClient
    .Users
    .GetAsync(requestConfiguration =>
        requestConfiguration.QueryParameters.Select = new string[] {"id", "createdDateTime"});
List<User> userList = usersResponse.Value;
@maisarissi
maisarissi / BackingStore.cs
Last active February 8, 2023 20:29
msgraph-dotnet-v5-rc-backing-store
//get the object
var @event = await graphServiceClient
    .Me.Events["event-id"]
    .GetAsync();
//the backing store will keep track that the property change and send the updated value.
@event.Recurrence = null;// set to null
//update the object
await graphServiceClient.Me.Events["event-id"]
@maisarissi
maisarissi / NewRequest.cs
Last active February 8, 2023 20:24
msgraph-dotnet-v5-rc-new-request
//create user using v5
var user = new User()
{
    DisplayName= "Adele V",
};
await graphServiceClient
.Users
.PostAsync(user);
@maisarissi
maisarissi / OldRequest.cs
Last active February 8, 2023 20:25
msgraph-dotnet-v4-create-user
//create user using v4
var user = new User()
{
    DisplayName = "Adele V",
};
await graphServiceClient
.Users
.Request()
.AddAsync(user);
@maisarissi
maisarissi / ParameterObject.cs
Last active February 9, 2023 13:58
msgraph-dotnet-v5-rc-parameter-object
//var message = ....
//var saveToSentItems = ...
var body = new SendMailPostRequestBody
{
Message = message,
    SaveToSentItems = saveToSentItems
};
await graphServiceClient.Me