private static async Task AddAppToTeam(IGraphRestApiService graphClient, string teamId, string channelId, string teamsAppId, Position position) { var teamsApps = await graphClient.ListTeamsApps(teamsAppId); var teamApp = teamsApps.Items.FirstOrDefault(); if (!string.IsNullOrEmpty(teamApp?.Id)) { var appId = $"https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/{teamApp.Id}"; await graphClient.AddAppToTeam(teamId, new TeamsApp { TeamsAppId = appId }); var contentUrl = $"{ConfigurationManager.AppSettings["BaseUrl"]}/StaticViews/TeamTab.html?positionId={position.PositionId}"; await graphClient.AddTab(teamId, channelId, new TeamsTab { TeamsAppId = appId, DisplayName = position.PositionExternalId, Configuration = new TeamsTabConfiguration { EntityId = position.PositionId.ToString(), ContentUrl = contentUrl, WebsiteUrl = contentUrl + "&web=1" } }); } }
private async Task <string[]> GetTeamMemberIds(IGraphRestApiService graphClient, Position position, User requester) { var result = new HashSet <string> { requester.Id }; var hiringManager = position.HiringManager; if (hiringManager != null && hiringManager.DirectReportIds.HasValue()) { var ids = hiringManager.DirectReportIds .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => Convert.ToInt32(x)); var members = await _databaseContext.Recruiters .Where(x => ids.Contains(x.RecruiterId)) .ToListAsync(); // because of demo, we don't know user upn and have to build on the flight var domain = new MailAddress(requester.UserPrincipalName).Host; foreach (var member in members) { var upn = $"{member.Alias}@{domain}"; var user = await graphClient.GetUserByUpn(upn); if (user != null) { result.Add(user.Id); } } } return(result.Select(CovertIdToOdataResourceFormat).ToArray()); }
private static Task <Group> CreateGroup(IGraphRestApiService graphClient, string positionId, string[] ownerIds, string[] memberIds) => graphClient.CreateGroup(new Group { DisplayName = $"Position {positionId}", MailNickname = positionId, Description = $"Everything about position {positionId}", Visibility = "Private", Owners = ownerIds, Members = memberIds, GroupTypes = new[] { "Unified" }, // Office 365 (aka unified group) MailEnabled = true, // true if creating an Office 365 Group SecurityEnabled = false // false if creating an Office 365 group });
private static Task <Team> CreateTeam(IGraphRestApiService graphClient, string groupId) => graphClient.CreateTeamForGroup(groupId, new Team { GuestSettings = new TeamPerRoleSettings { AllowCreateUpdateChannels = false, AllowDeleteChannels = false }, MemberSettings = new TeamPerRoleSettings { AllowCreateUpdateChannels = true }, MessagingSettings = new TeamMessagingSettings { AllowUserEditMessages = true, AllowUserDeleteMessages = true }, FunSettings = new TeamFunSettings { AllowGiphy = true, GiphyContentRating = "strict" } });
private static async Task <string[]> GetTeamOwnerIds(IGraphRestApiService graphClient, Position position, User requester) { var result = new HashSet <string> { requester.Id }; var hiringManager = position.HiringManager; if (hiringManager != null) { // because of demo, we don't know user upn and have to build on the flight var domain = new MailAddress(requester.UserPrincipalName).Host; var upn = $"{hiringManager.Alias}@{domain}"; var user = await graphClient.GetUserByUpn(upn); if (user != null) { result.Add(user.Id); } } return(result.Select(CovertIdToOdataResourceFormat).ToArray()); }
private static Task <Channel> CreateChannel(IGraphRestApiService graphClient, string teamId) => graphClient.CreateChannelForTeam(teamId, new Channel { DisplayName = "Candidates", Description = "Discussion about interview, feedback, etc." });