Exemplo n.º 1
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)
            });
        }