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); }
public async Task <bool> UploadFileAsync(GraphServiceClient graphService, UploadFileModel model) { try { var graphToken = AuthenticationHelper.GetGraphAccessTokenAsync(); var propertyGroup = await graphService.GetGroupByDisplayNameAsync(model.PropertyTitle); if (propertyGroup == null) { return(false); } DriveItem driveItem = new DriveItem(); driveItem.Name = model.File.FileName; driveItem.File = new Microsoft.Graph.File(); driveItem = await graphService.Groups[propertyGroup.Id].Drive.Root.Children.Request().AddAsync(driveItem); await graphService.Groups[propertyGroup.Id].Drive.Items[driveItem.Id].Content.Request().PutAsync <DriveItem>(model.File.InputStream); } catch (Exception el) { throw el; } return(false); }
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); }
public async Task<bool> UploadFileAsync(GraphServiceClient graphService, UploadFileModel model) { try { var graphToken = AuthenticationHelper.GetGraphAccessTokenAsync(); var propertyGroup = await graphService.GetGroupByDisplayNameAsync(model.PropertyTitle); if (propertyGroup == null) return false; DriveItem driveItem = new DriveItem(); driveItem.Name = model.File.FileName; driveItem.File = new Microsoft.Graph.File(); driveItem = await graphService.Groups[propertyGroup.Id].Drive.Root.Children.Request().AddAsync(driveItem); await graphService.Groups[propertyGroup.Id].Drive.Items[driveItem.Id].Content.Request().PutAsync<DriveItem>(model.File.InputStream); } catch (Exception el) { throw el; } return false; }