public static async Task RemoveUsersFromGroup(string groupId, IGroupRequestBuilder group, List <User> users, TraceWriter log) { for (int i = 0; i < users.Count; i++) { var user = users[i]; log.Info($"Removing user {user.Id} from group {groupId}"); await group.Members[user.Id].Reference.Request().DeleteAsync(); } }
private async Task <HyperLink[]> GetConversationsAsync(IGroupRequestBuilder groupFethcer, string groupMail) { var conversations = await groupFethcer.Conversations.Request().GetAllAsync(); var webUrl = string.Format("{0}owa/#path=/group/{1}/mail", AADAppSettings.OutlookUrl, groupMail); return(conversations.Select(i => new HyperLink { Title = i.Topic, WebUrl = webUrl }).ToArray()); }
public static async Task<User[]> GetGroupMembersAsync(this GraphServiceClient service, IGroupRequestBuilder groupFetcher) { List<User> users = new List<User>(); var collection = await groupFetcher.Members.Request().GetAllAsnyc(); foreach (var item in collection) { var findUser = await service.Users[item.Id].Request().Select("id,displayName,department,officeLocation,mail,mobilePhone,businessPhones,jobTitle").GetAsync(); if (findUser != null) users.Add(findUser); } return users.ToArray(); }
private async Task <List <File> > GetGroupFilesAsync(IGroupRequestBuilder groupFetcher) { var list = new List <File>(); Graph.DriveItem[] files = null; try { files = await groupFetcher.Drive.Root.Children.Request().GetAllAsync(); } catch { return(list); } foreach (var file in files) { var fileId = Regex.Match(file.ETag, @"{.*}").Captures[0].Value; string url; if (file.Name.ToLower().Contains(".docx") || file.Name.ToLower().Contains(".pptx") || file.Name.ToLower().Contains(".xlsx")) { url = string.Format("{0}_layouts/15/WopiFrame.aspx?sourcedoc={1}&file={2}&action=default", Regex.Match(file.WebUrl, @"\S*/sites/\S*?/", RegexOptions.IgnoreCase).Captures[0].Value, fileId, file.Name); } else { url = file.WebUrl; } if (file.Folder == null) { list.Add(new File { id = file.Id, name = file.Name, webUrl = url, dateTimeLastModified = file.LastModifiedDateTime.HasValue ? file.LastModifiedDateTime.Value : new DateTimeOffset() }); } } return(list); }
/// <summary> /// Get SectionDetailsViewModel of the specified section /// </summary> public async Task <SectionDetailsViewModel> GetSectionDetailsViewModelAsync(string schoolId, string classId, IGroupRequestBuilder group) { var school = await educationServiceClient.GetSchoolAsync(schoolId); var @class = await educationServiceClient.GetClassAsync(classId); @class.Teachers = @class.Members.Where(c => c.PrimaryRole == EducationRole.Teacher).ToList(); var driveRootFolder = await group.Drive.Root.Request().GetAsync(); //var schoolTeachers = await educationServiceClient.GetAllTeachersAsync(school.SchoolNumber); var schoolTeachers = await educationServiceClient.GetAllTeachersAsync(school.ExternalId); //this works in our tenant foreach (var sectionTeacher in @class.Teachers) { schoolTeachers = schoolTeachers.Where(t => t.Id != sectionTeacher.Id).ToArray(); } foreach (var user in @class.Students) { var seat = dbContext.ClassroomSeatingArrangements.FirstOrDefault(c => c.O365UserId == user.Id && c.ClassId == classId); user.Position = seat?.Position ?? 0; var userInDB = dbContext.Users.Where(c => c.O365UserId == user.Id).FirstOrDefault(); user.FavoriteColor = userInDB == null ? "" : userInDB.FavoriteColor; } return(new SectionDetailsViewModel { School = school, Class = @class, Conversations = await group.Conversations.Request().GetAllAsync(), //Conversations = Array.Empty<Conversation>(), SeeMoreConversationsUrl = string.Format(Constants.O365GroupConversationsUrl, @class.MailNickname), DriveItems = await group.Drive.Root.Children.Request().GetAllAsync(), //DriveItems = Array.Empty<DriveItem>(), SeeMoreFilesUrl = driveRootFolder.WebUrl, SchoolTeachers = schoolTeachers }); }
/// <summary> /// Get SectionDetailsViewModel of the specified section /// </summary> public async Task <SectionDetailsViewModel> GetSectionDetailsViewModelAsync(string schoolId, string classId, IGroupRequestBuilder group) { var school = await educationServiceClient.GetSchoolAsync(schoolId); var section = await educationServiceClient.GetSectionAsync(classId); var driveRootFolder = await group.Drive.Root.Request().GetAsync(); foreach (var user in section.Students) { var seat = dbContext.ClassroomSeatingArrangements.Where(c => c.O365UserId == user.O365UserId && c.ClassId == classId).FirstOrDefault(); user.Position = seat?.Position ?? 0; var userInDB = dbContext.Users.Where(c => c.O365UserId == user.O365UserId).FirstOrDefault(); user.FavoriteColor = userInDB == null ? "" : userInDB.FavoriteColor; } return(new SectionDetailsViewModel { School = school, Section = section, Conversations = await group.Conversations.Request().GetAllAsync(), SeeMoreConversationsUrl = string.Format(Constants.O365GroupConversationsUrl, section.Email), DriveItems = await group.Drive.Root.Children.Request().GetAllAsync(), SeeMoreFilesUrl = driveRootFolder.WebUrl }); }
public async Task <SectionDetailsViewModel> GetSectionDetailsViewModelAsync(string schoolId, string sectionId, IGroupRequestBuilder group) { var school = await educationServiceClient.GetSchoolAsync(schoolId); var section = await educationServiceClient.GetSectionAsync(sectionId); var driveRootFolder = await group.Drive.Root.Request().GetAsync(); return(new SectionDetailsViewModel { School = school, Section = section, Conversations = await group.Conversations.Request().GetAllAsync(), SeeMoreConversationsUrl = string.Format(Constants.O365GroupConversationsUrl, section.Email), DriveItems = await group.Drive.Root.Children.Request().GetAllAsync(), SeeMoreFilesUrl = driveRootFolder.WebUrl }); }
private async Task<HyperLink[]> GetConversationsAsync(IGroupRequestBuilder groupFethcer, string groupMail) { var conversations = await groupFethcer.Conversations.Request().GetAllAsnyc(); var webUrl = string.Format("{0}owa/#path=/group/{1}/mail", AADAppSettings.OutlookUrl, groupMail); return conversations.Select(i => new HyperLink { Title = i.Topic, WebUrl = webUrl }).ToArray(); }
private async Task<List<File>> GetGroupFilesAsync(IGroupRequestBuilder groupFetcher) { var list = new List<File>(); Graph.DriveItem[] files = null; try { files = await groupFetcher.Drive.Root.Children.Request().GetAllAsnyc(); } catch { return list; } foreach (var file in files) { var fileId = Regex.Match(file.ETag, @"{.*}").Captures[0].Value; string url; if (file.Name.ToLower().Contains(".docx") || file.Name.ToLower().Contains(".pptx") || file.Name.ToLower().Contains(".xlsx")) { url = string.Format("{0}_layouts/15/WopiFrame.aspx?sourcedoc={1}&file={2}&action=default", Regex.Match(file.WebUrl, @"\S*/sites/\S*?/", RegexOptions.IgnoreCase).Captures[0].Value, fileId, file.Name); } else { url = file.WebUrl; } if (file.Folder == null) { list.Add(new File { id = file.Id, name = file.Name, webUrl = url, dateTimeLastModified = file.LastModifiedDateTime.HasValue ? file.LastModifiedDateTime.Value : new DateTimeOffset() }); } } return list; }
public static async Task <User[]> GetGroupMembersAsync(this GraphServiceClient service, IGroupRequestBuilder groupFetcher) { List <User> users = new List <User>(); var collection = await groupFetcher.Members.Request().GetAllAsnyc(); foreach (var item in collection) { var findUser = await service.Users[item.Id].Request().Select("id,displayName,department,officeLocation,mail,mobilePhone,businessPhones,jobTitle").GetAsync(); if (findUser != null) { users.Add(findUser); } } return(users.ToArray()); }