public async Task CreateUnifiedGroupsForPropertiesAsync(GraphService graphService)
        {
            var properties = Task.Run(() => CSOMUtil.GetListItems(clientContext, "Properties"));

            var members = new List <IUser>();

            {
                var dispatcher = await graphService.GetFirstUserAsync(u => u.mail == AppSettings.DispatcherEmail);

                var inspectors = await graphService.GetGroupMembersAsync("Inspectors");

                var repairPeople = await graphService.GetGroupMembersAsync("Repair People");

                if (dispatcher != null)
                {
                    members.Add(dispatcher);
                }
                members.AddRange(inspectors);
                members.AddRange(repairPeople);
            }

            foreach (var property in await properties)
            {
                var group = await graphService.GetGroupByDisplayNameAsync((string)property["Title"]);

                if (group == null)
                {
                    group = await CreateUnifiedGroupForPropertyAsync(graphService, property, members);
                }
                property["sl_group"] = group.objectId;
                property.Update();
            }
            clientContext.ExecuteQuery();
        }
Exemple #2
0
        public async Task CreateUnifiedGroupsForPropertiesAsync(GraphServiceClient graphService, string graphAccessToken)
        {
            var properties = Task.Run(() => CSOMUtil.GetListItems(clientContext, "Properties"));

            var members = new List <Graph.User>();

            {
                var queryUsers = (await graphService.Users.Request().Filter(string.Format("mail eq '{0}'", AppSettings.DispatcherEmail)).GetAsync()).CurrentPage;
                var dispatcher = queryUsers.Count > 0 ? queryUsers[0]: null;
                if (dispatcher == null)
                {
                    return;
                }

                var inspectors = await graphService.GetGroupMembersAsync("Inspectors");

                var repairPeople = await graphService.GetGroupMembersAsync("Repair People");

                if (dispatcher != null)
                {
                    members.Add(dispatcher);
                }
                members.AddRange(inspectors);
                members.AddRange(repairPeople);
            }

            foreach (var property in await properties)
            {
                var group = await graphService.GetGroupByDisplayNameAsync((string)property["Title"]);

                if (group == null)
                {
                    group = await CreateUnifiedGroupForPropertyAsync(graphService, graphAccessToken, property, members);
                }

                property["sl_group"] = group.Id;
                property.Update();
            }
            clientContext.ExecuteQuery();

            await UpdateGroupPhotoAsync(graphService);
        }