private static async Task <SharePointList> CreateChallengingPassengersListAsync(GraphService graphClient, string groupId, string channelId)
        {
            // Get the team site
            var teamSite = await graphClient.GetTeamSiteAsync(groupId);

            var challengingPassengers = new SharePointList
            {
                DisplayName = "Challenging Passengers",
                Columns     = new List <ColumnDefinition>()
                {
                    new ColumnDefinition
                    {
                        Name = "Name",
                        Text = new TextColumn()
                    },
                    new ColumnDefinition
                    {
                        Name = "SeatNumber",
                        Text = new TextColumn()
                    },
                    new ColumnDefinition
                    {
                        Name = "Notes",
                        Text = new TextColumn()
                    }
                }
            };

            // Create the list
            var createdList = await graphClient.CreateSharePointListAsync(teamSite.Id, challengingPassengers);

            if (createTabs)
            {
                // Add the list as a team tab
                var listTab = new TeamsChannelTab
                {
                    Name          = "Challenging Passengers",
                    TeamsAppId    = "com.microsoft.teamspace.tab.web",
                    Configuration = new TeamsChannelTabConfiguration
                    {
                        ContentUrl = createdList.WebUrl,
                        WebsiteUrl = createdList.WebUrl
                    }
                };

                await graphClient.AddTeamChannelTab(groupId, channelId, listTab);
            }

            return(createdList);
        }
        private static async Task CreatePreflightPlanAsync(GraphService graphClient, string groupId, string channelId, DateTimeOffset departureTime)
        {
            // Create a "Pre-flight checklist" plan
            var preFlightCheckList = new Plan
            {
                Title = "Pre-flight Checklist",
                Owner = groupId
            };

            var createdPlan = await graphClient.CreatePlanAsync(preFlightCheckList);

            logger.Info("Create plan");

            // Create buckets
            var toDoBucket = new Bucket
            {
                Name   = "To Do",
                PlanId = createdPlan.Id
            };

            var createdToDoBucket = await graphClient.CreateBucketAsync(toDoBucket);

            var completedBucket = new Bucket
            {
                Name   = "Completed",
                PlanId = createdPlan.Id
            };

            var createdCompletedBucket = await graphClient.CreateBucketAsync(completedBucket);

            // Create tasks in to-do bucket
            var preFlightInspection = new PlannerTask
            {
                Title       = "Perform pre-flight inspection of aircraft",
                PlanId      = createdPlan.Id,
                BucketId    = createdToDoBucket.Id,
                DueDateTime = departureTime.ToUniversalTime()
            };

            await graphClient.CreatePlannerTaskAsync(preFlightInspection);

            var ensureFoodBevStock = new PlannerTask
            {
                Title       = "Ensure food and beverages are fully stocked",
                PlanId      = createdPlan.Id,
                BucketId    = createdToDoBucket.Id,
                DueDateTime = departureTime.ToUniversalTime()
            };

            await graphClient.CreatePlannerTaskAsync(ensureFoodBevStock);

            if (createTabs)
            {
                // Add planner tab to General channel
                var plannerTab = new TeamsChannelTab
                {
                    Name          = "Pre-flight Checklist",
                    TeamsAppId    = "com.microsoft.teamspace.tab.planner",
                    Configuration = new TeamsChannelTabConfiguration
                    {
                        EntityId   = createdPlan.Id,
                        ContentUrl = $"https://tasks.office.com/{tenantName}/Home/PlannerFrame?page=7&planId={createdPlan.Id}&auth_pvr=Orgid&auth_upn={{upn}}&mkt={{locale}}",
                        RemoveUrl  = $"https://tasks.office.com/{tenantName}/Home/PlannerFrame?page=13&planId={createdPlan.Id}&auth_pvr=Orgid&auth_upn={{upn}}&mkt={{locale}}",
                        WebsiteUrl = $"https://tasks.office.com/{tenantName}/Home/PlanViews/{createdPlan.Id}"
                    }
                };

                await graphClient.AddTeamChannelTab(groupId, channelId, plannerTab);
            }
        }
Ejemplo n.º 3
0
        private static async Task CreateSharePointPageAsync(string groupId, string channelId, float flightNumber)
        {
            try
            {
                // Get the team site
                var teamSite = await graphClient.GetTeamSiteAsync(groupId);

                logger.LogInformation("Got team site");

                // Initialize page
                var sharePointPage = new SitePage
                {
                    Name  = "Crew.aspx",
                    Title = $"Flight {flightNumber} Crew"
                };

                var webParts = new List <WebPart>
                {
                    new WebPart
                    {
                        Type = webPartId,
                        Data = new SitePageData
                        {
                            AdditionalData = new Dictionary <string, object>
                            {
                                { "dataVersion", "1.0" },
                                { "properties", new Dictionary <string, object>
                                  {
                                      { "description", "CrewBadges" }
                                  } }
                            }
                        }
                    }
                };

                sharePointPage.WebParts = webParts;

                var createdPage = await graphClient.CreateSharePointPageAsync(teamSite.Id, sharePointPage);

                logger.LogInformation("Created crew page");

                // Publish the page
                await graphClient.PublishSharePointPageAsync(teamSite.Id, createdPage.Id);

                var pageUrl = createdPage.WebUrl.StartsWith("https") ? createdPage.WebUrl :
                              $"{teamSite.WebUrl}/{createdPage.WebUrl}";

                logger.LogInformation("Published crew page");

                // Add the list as a team tab
                var pageTab = new TeamsTab
                {
                    Name          = createdPage.Title,
                    TeamsAppId    = "com.microsoft.teamspace.tab.web",
                    Configuration = new TeamsTabConfiguration
                    {
                        ContentUrl = pageUrl,
                        WebsiteUrl = pageUrl
                    }
                };

                await graphClient.AddTeamChannelTab(groupId, channelId, pageTab);

                logger.LogInformation("Added crew page as Teams tab");
            }
            catch (Exception ex)
            {
                logger.LogWarning($"Failed to create crew page: ${ex.ToString()}");
            }
        }