Example #1
0
        public void Init()
        {
            festiClient   = new Mock <IFestiClient>().Object;
            statusService = new Mock <INetStatusService>().Object;
            ListMock      = new InspectorListViewModel(festiClient, mapperMock.Object, statusService);
            window        = new Mock <IClosable>();
            mapperMock    = new Mock <IMapper>();
            //ListMock.Setup(mock => mock.ViewModels).Returns(CLASSMAKEN));
            AddQVM = new AddInspectorViewModel(new Mock <IUserRepository>().Object, ListMock, mapperMock.Object, festiClient);
            //AddQVM.l


            //MockRepo.Setup(elem => elem.InsertAsync(Question)).Returns(Task.CompletedTask);
            //QfactoryMock.Setup(mock => mock.QuestionTypes== "open");
            //FestiMClientMock = new Mock<FestiMSClient>();
        }
        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));
        }