i have this Method Async to create a group, using the nuget Microsoft Graph, I wanted to know if they help me to add a user to this group in the same moment that is believed.
I have tried it, but the class "Group" in your content, "Owners", "Members" and "MemberOf" they are Interfaces.
i tried that after of to created the group add un Owner, as well a member; but it does not work.
this is one of my proof: User jona = await graphClient.Me.Request().GetAsync(); // This line of code brings all the information of me user logged group.Owners.add(jona); // this lines before of the condition "if"
but appears a exception "SystemNullException".
public async Task<List<ResultsItem>> CreateGroup(GraphServiceClient graphClient)
{
List<ResultsItem> items = new List<ResultsItem>();
string guid = Guid.NewGuid().ToString();
Group group = await graphClient.Groups.Request().AddAsync(new Group
{
GroupTypes = new List<string> { "Unified" },
DisplayName = Resource.Group + guid.Substring(0, 8),
Description = Resource.Group + guid,
MailNickname = Resource.Group.ToLower() + guid.Substring(0, 8),
MailEnabled = false,
SecurityEnabled = false
});
if (group != null)
{
// Get group properties.
items.Add(new ResultsItem
{
Display = group.DisplayName,
Id = group.Id,
Properties = new Dictionary<string, object>
{
{ Resource.Prop_Description, group.Description },
{ Resource.Prop_Email, group.Mail },
{ Resource.Prop_Created, group.AdditionalData["createdDateTime"] }, // Temporary solution for a known SDK problem.
{ Resource.Prop_Id, group.Id }
}
});
}
return items;
}