public async Task <ActionResult> AddInspectorExecute(AddInspectorViewModel viewModel)
        {
            // Acquire all the fixed resources we'll need.
            var graphService = await AuthenticationHelper.GetGraphServiceAsync(AADAppSettings.GraphResourceUrl);

            User  candidate  = await graphService.Users[viewModel.SelectedCandidate].Request().GetAsync();
            Group inspectors = await graphService.GetGroupByDisplayNameAsync("Inspectors");

            Group gettingStarted = await graphService.GetGroupByDisplayNameAsync("GettingStarted");

            Plan gettingStartedPlan = await PlanService.GetPlanAsync(gettingStarted);

            Bucket bucket = await PlanService.GetBucketByNameAsync(gettingStartedPlan, "Unstarted");

            // Add the user to the GettingStarted group where newcomers share onboarding tasks
            try
            {
                await graphService.Groups[gettingStarted.Id].Members.References.Request().AddAsync(candidate);
            }
            catch
            {
                // Assume failure means it's already in the group - as it often is during demos!
            }


            // Iterate over the 'NewHireTasks' sharepoint list with the new preview API.
            var site = await SharePointService.GetSiteByPathAsync("/sites/SuiteLevelAppDemo");

            NewHireTaskListitem[] listitems = await SharePointService.GetListItemsFromSiteList <NewHireTaskListitem>(site, "NewHireTasks");

            foreach (NewHireTaskListitem listItem in listitems)
            {
                try
                {
                    // Make a Planner task in the 'GettingStarted' group for each task in the NewHireTasks list.
                    PlannerTask created = await PlanService.CreateTaskAsync(new PlannerTask
                    {
                        title           = listItem.Title,
                        assignedTo      = candidate.Id,
                        percentComplete = 0,
                        planId          = bucket.planId,
                        bucketId        = bucket.id,
                    });

                    await PlanService.UpdateTaskDescriptionAsync(created, listItem.Description);
                }
                catch
                {
                    // Move on to the next if anything goes wrong.
                    continue;
                }
            }

            // Make sure new user has all the licenses they need.
            await GraphServiceExtension.AssignLicenseAsync(graphService, candidate);

            // Add the user to the Inspector's group
            await graphService.Groups[inspectors.Id].Members.References.Request().AddAsync(candidate);

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public async Task CreateO365TaskAsync(GraphServiceClient graphService, ScheduleRepairModel model)
        {
            var incident = await GetIncidentByIdAsync(model.IncidentId);

            var repairPeopleMail = (await GetRepairPeopleByEmailAddressAsync(model.RepairPeopleSelectedValue)).sl_emailaddress;
            var repairPeopleList = (await graphService.Users.Request().Filter(string.Format("mail eq '{0}'", repairPeopleMail)).Top(1).GetAsync()).CurrentPage;
            var repairPeople     = repairPeopleList.Count > 0 ? repairPeopleList[0] : null;

            if (repairPeople == null)
            {
                return;
            }
            var me           = graphService.Me.Request().GetAsync();
            var property     = incident.sl_propertyID;
            var unifiedGroup = await graphService.Groups[property.sl_group].Request().GetAsync();

            var plan = PlanService.GetPlanAsync(unifiedGroup);

            if (await plan == null)
            {
                return;
            }

            var incidentBucket = PlanService.CreateBucketAsync(new Bucket
            {
                name   = string.Format("Incident [{0}]", incident.Id),
                planId = (await plan).id
            });

            await PlanService.CreateTaskAsync(new PlannerTask
            {
                title           = "Clean up work site",
                assignedTo      = repairPeople.Id,
                assignedBy      = (await me).Id,
                percentComplete = 0,
                planId          = (await incidentBucket).planId,
                bucketId        = (await incidentBucket).id,
                dueDateTime     = new DateTimeOffset(model.TimeSlotsSelectedValue)
            });

            await PlanService.CreateTaskAsync(new PlannerTask
            {
                title           = "Have property owner sign repair completion document",
                assignedTo      = repairPeople.Id,
                assignedBy      = (await me).Id,
                percentComplete = 0,
                planId          = (await incidentBucket).planId,
                bucketId        = (await incidentBucket).id,
                dueDateTime     = new DateTimeOffset(model.TimeSlotsSelectedValue)
            });

            await PlanService.CreateTaskAsync(new PlannerTask
            {
                title           = "Call property owner to confirm repair appointment",
                assignedTo      = repairPeople.Id,
                assignedBy      = (await me).Id,
                percentComplete = 0,
                planId          = (await incidentBucket).planId,
                bucketId        = (await incidentBucket).id,
                dueDateTime     = new DateTimeOffset(model.TimeSlotsSelectedValue)
            });
        }