public async Task ScheduleRepairAsync(GraphServiceClient graphService, ScheduleRepairModel model) { var incident = await GetIncidentByIdAsync(model.IncidentId); var repairPeople = await GetRepairPeopleByEmailAddressAsync(model.RepairPeopleSelectedValue); string body = string.Format("<p>{0}</p><br/><br/><p>Incident ID: <span id='x_IncidentID'>{1}</span><br/><br/>Property ID: <span id='x_PropertyID'>{2}</span></p>", incident.sl_dispatcherComments, incident.Id, incident.sl_propertyID.Id ); var attendee = new Graph.Attendee { EmailAddress = new EmailAddress { Address = repairPeople.sl_emailaddress, Name = repairPeople.Title }, Type = AttendeeType.Required, Status = new ResponseStatus() }; var newEvent = new Graph.Event { Subject = "Repair Event", Body = new ItemBody { Content = body, ContentType = BodyType.Html }, ShowAs = FreeBusyStatus.Busy, Start = new DateTimeTimeZone { DateTime = model.TimeSlotsSelectedValue.ToString(), TimeZone = TimeZone.CurrentTimeZone.StandardName }, End = new DateTimeTimeZone { DateTime = (model.TimeSlotsSelectedValue.AddHours(1)).ToString(), TimeZone = TimeZone.CurrentTimeZone.StandardName }, Location = new Location { Address = new PhysicalAddress(), // Coordinates = new outlookGeoCoordinates(), DisplayName = incident.sl_roomID.Title, }, Attendees = new Attendee[] { attendee } }; try { newEvent = await graphService.Me.Events.Request().AddAsync(newEvent); } catch { } }
public async Task UpdateRepairScheduleInfoToIncidentAsync(ScheduleRepairModel model) { ScheduleRepairUpdate updateJson = new ScheduleRepairUpdate(); updateJson.sl_dispatcherComments = model.DispatcherComments; updateJson.sl_repairScheduled = model.TimeSlotsSelectedValue.ToUniversalTime(); updateJson.sl_repairPerson = model.RepairPeopleSelectedValue; updateJson.__metadata = new metadata { type = "SP.Data.IncidentsListItem" }; await SuiteLevelWebApp.Utils.RestHelper.PostRestDataToDemoSiteAsync("/_api/lists/GetByTitle('Incidents')/Items(" + model.IncidentId + ")", JsonConvert.SerializeObject(updateJson), _token); }
public async Task<ActionResult> ScheduleRepair(ScheduleRepairModel model) { var sharePointToken = AuthenticationHelper.GetAccessTokenAsync(AppSettings.DemoSiteServiceResourceId); var graphService = AuthenticationHelper.GetGraphServiceAsync(); var tasksService = new TasksService(await sharePointToken); var dashboardModel = new Dashboard(await sharePointToken); await dashboardModel.UpdateRepairScheduleInfoToIncidentAsync(model) .ContinueWith(async task => await tasksService.CompleteRepairAssignmentTaskAsync(model.IncidentId)); await dashboardModel.ScheduleRepairAsync(await graphService, model); await dashboardModel.CreateGroupRepairEventAsync(await graphService, model); return RedirectToAction("Index"); }
public async Task<ActionResult> ScheduleRepair(ScheduleRepairModel model) { model.TimeSlotsSelectedValue = DateTime.ParseExact(string.Format("{0} {1}:00", model.TimeSlotsSelectedDateValue, model.TimeSlotsSelectedHoursValue), "yyyy-MM-dd HH:mm", null); var sharePointToken = AuthenticationHelper.GetAccessTokenAsync(AppSettings.DemoSiteServiceResourceId); var graphService = AuthenticationHelper.GetGraphServiceAsync(AADAppSettings.GraphResourceUrl); var tasksService = new TasksService(await sharePointToken); var dashboardModel = new Dashboard(await sharePointToken); await dashboardModel.UpdateRepairScheduleInfoToIncidentAsync(model) .ContinueWith(async task => await tasksService.CompleteRepairAssignmentTaskAsync(model.IncidentId)); await dashboardModel.ScheduleRepairAsync(await graphService, model); await dashboardModel.CreateGroupRepairEventAsync(await graphService, model); await dashboardModel.CreateO365TaskAsync(await graphService, model); return RedirectToAction("Index"); }
public async Task <Graph.Event> CreateGroupRepairEventAsync(GraphService graphService, ScheduleRepairModel model) { var incident = await GetIncidentByIdAsync(model.IncidentId); var property = incident.sl_propertyID; var unifiedGroupFetcher = graphService.groups.GetById(property.sl_group); string body = string.Format("<p>{0}</p><br/><br/><p>Incident ID: <span id='x_IncidentID'>{1}</span><br/><br/>Property ID: <span id='x_PropertyID'>{2}</span></p>", incident.sl_dispatcherComments, incident.Id, property.Id ); var newEvent = new Graph.Event { Subject = "Repair Event", Body = new Graph.ItemBody { Content = body, ContentType = Graph.BodyType.HTML }, ShowAs = Graph.FreeBusyStatus.Busy, Start = model.TimeSlotsSelectedValue.ToUniversalTime(), End = (model.TimeSlotsSelectedValue.AddHours(1)).ToUniversalTime(), Location = new Graph.Location { DisplayName = incident.sl_roomID.Title }, Reminder = 60 * 24 }; await unifiedGroupFetcher.Events.AddEventAsync(newEvent); return(newEvent); }
public async Task <Graph.Event> ScheduleRepairAsync(GraphService graphService, ScheduleRepairModel model) { var incident = await GetIncidentByIdAsync(model.IncidentId); var repairPeople = await GetRepairPeopleByEmailAddressAsync(model.RepairPeopleSelectedValue); string body = string.Format("<p>{0}</p><br/><br/><p>Incident ID: <span id='x_IncidentID'>{1}</span><br/><br/>Property ID: <span id='x_PropertyID'>{2}</span></p>", incident.sl_dispatcherComments, incident.Id, incident.sl_propertyID.Id ); var attendee = new Graph.Attendee { EmailAddress = new Graph.EmailAddress { Address = repairPeople.sl_emailaddress, Name = repairPeople.Title }, Type = Graph.AttendeeType.Required }; var newEvent = new Graph.Event { Subject = "Repair Event", Body = new Graph.ItemBody { Content = body, ContentType = Graph.BodyType.HTML }, ShowAs = Graph.FreeBusyStatus.Busy, Start = model.TimeSlotsSelectedValue.ToUniversalTime(), End = (model.TimeSlotsSelectedValue.AddHours(1)).ToUniversalTime(), Location = new Graph.Location { DisplayName = incident.sl_roomID.Title }, Attendees = new Graph.Attendee[] { attendee } }; await graphService.Me.Events.AddEventAsync(newEvent); return(newEvent); }
public async Task CreateGroupRepairEventAsync(GraphServiceClient graphService, ScheduleRepairModel model) { var incident = await GetIncidentByIdAsync(model.IncidentId); var property = incident.sl_propertyID; var unifiedGroupFetcher = graphService.Groups[property.sl_group]; string body = string.Format("<p>{0}</p><br/><br/><p>Incident ID: <span id='x_IncidentID'>{1}</span><br/><br/>Property ID: <span id='x_PropertyID'>{2}</span></p>", incident.sl_dispatcherComments, incident.Id, property.Id ); var newEvent = new Graph.Event { Subject = "Repair Event", Body = new ItemBody { Content = body, ContentType = BodyType.Html }, ShowAs = FreeBusyStatus.Busy, Start = new DateTimeTimeZone { DateTime = model.TimeSlotsSelectedValue.ToString(), TimeZone = TimeZone.CurrentTimeZone.StandardName }, End = new DateTimeTimeZone { DateTime = (model.TimeSlotsSelectedValue.AddHours(1)).ToString(), TimeZone = TimeZone.CurrentTimeZone.StandardName }, Location = new Location { DisplayName = incident.sl_roomID.Title, Address = new PhysicalAddress(), //coordinates = new outlookGeoCoordinates() }, ReminderMinutesBeforeStart = 60 * 24 }; try { newEvent = await unifiedGroupFetcher.Events.Request().AddAsync(newEvent); } catch { } }
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) }); }
public async Task<Graph.Event> CreateGroupRepairEventAsync(GraphService graphService, ScheduleRepairModel model) { var incident = await GetIncidentByIdAsync(model.IncidentId); var property = incident.sl_propertyID; var unifiedGroupFetcher = graphService.groups.GetById(property.sl_group); string body = string.Format("<p>{0}</p><br/><br/><p>Incident ID: <span id='x_IncidentID'>{1}</span><br/><br/>Property ID: <span id='x_PropertyID'>{2}</span></p>", incident.sl_dispatcherComments, incident.Id, property.Id ); var newEvent = new Graph.Event { Subject = "Repair Event", Body = new Graph.ItemBody { Content = body, ContentType = Graph.BodyType.HTML }, ShowAs = Graph.FreeBusyStatus.Busy, Start = model.TimeSlotsSelectedValue.ToUniversalTime(), End = (model.TimeSlotsSelectedValue.AddHours(1)).ToUniversalTime(), Location = new Graph.Location { DisplayName = incident.sl_roomID.Title }, Reminder = 60 * 24 }; await unifiedGroupFetcher.Events.AddEventAsync(newEvent); return newEvent; }
public async Task<Graph.Event> ScheduleRepairAsync(GraphService graphService, ScheduleRepairModel model) { var incident = await GetIncidentByIdAsync(model.IncidentId); var repairPeople = await GetRepairPeopleByEmailAddressAsync(model.RepairPeopleSelectedValue); string body = string.Format("<p>{0}</p><br/><br/><p>Incident ID: <span id='x_IncidentID'>{1}</span><br/><br/>Property ID: <span id='x_PropertyID'>{2}</span></p>", incident.sl_dispatcherComments, incident.Id, incident.sl_propertyID.Id ); var attendee = new Graph.Attendee { EmailAddress = new Graph.EmailAddress { Address = repairPeople.sl_emailaddress, Name = repairPeople.Title }, Type = Graph.AttendeeType.Required }; var newEvent = new Graph.Event { Subject = "Repair Event", Body = new Graph.ItemBody { Content = body, ContentType = Graph.BodyType.HTML }, ShowAs = Graph.FreeBusyStatus.Busy, Start = model.TimeSlotsSelectedValue.ToUniversalTime(), End = (model.TimeSlotsSelectedValue.AddHours(1)).ToUniversalTime(), Location = new Graph.Location { DisplayName = incident.sl_roomID.Title }, Attendees = new Graph.Attendee[] { attendee } }; await graphService.Me.Events.AddEventAsync(newEvent); return newEvent; }
public async Task UpdateRepairScheduleInfoToIncidentAsync(ScheduleRepairModel model) { ScheduleRepairUpdate updateJson = new ScheduleRepairUpdate(); updateJson.sl_dispatcherComments = model.DispatcherComments; updateJson.sl_repairScheduled = model.TimeSlotsSelectedValue.ToUniversalTime(); updateJson.sl_repairPerson = model.RepairPeopleSelectedValue; updateJson.__metadata = new metadata { type = "SP.Data.IncidentsListItem" }; await SuiteLevelWebApp.Utils.RestHelper.PostRestDataToDemoSiteAsync("/_api/lists/GetByTitle('Incidents')/Items(" + model.IncidentId + ")", JsonConvert.SerializeObject(updateJson), _token); }
public async Task CreateGroupRepairEventAsync(GraphServiceClient graphService, ScheduleRepairModel model) { var incident = await GetIncidentByIdAsync(model.IncidentId); var property = incident.sl_propertyID; var unifiedGroupFetcher = graphService.Groups[property.sl_group]; string body = string.Format("<p>{0}</p><br/><br/><p>Incident ID: <span id='x_IncidentID'>{1}</span><br/><br/>Property ID: <span id='x_PropertyID'>{2}</span></p>", incident.sl_dispatcherComments, incident.Id, property.Id ); var newEvent = new Graph.Event { Subject = "Repair Event", Body = new ItemBody { Content = body, ContentType = BodyType.Html }, ShowAs = FreeBusyStatus.Busy, Start = new DateTimeTimeZone { DateTime = model.TimeSlotsSelectedValue.ToString(), TimeZone = TimeZone.CurrentTimeZone.StandardName }, End = new DateTimeTimeZone { DateTime = (model.TimeSlotsSelectedValue.AddHours(1)).ToString(), TimeZone = TimeZone.CurrentTimeZone.StandardName }, Location = new Location { DisplayName = incident.sl_roomID.Title, Address = new PhysicalAddress(), //coordinates = new outlookGeoCoordinates() }, ReminderMinutesBeforeStart = 60 * 24 }; try { newEvent = await unifiedGroupFetcher.Events.Request().AddAsync(newEvent); } catch { } }
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 task { 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 task { 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 task { 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) }); }
public async Task ScheduleRepairAsync(GraphServiceClient graphService, ScheduleRepairModel model) { var incident = await GetIncidentByIdAsync(model.IncidentId); var repairPeople = await GetRepairPeopleByEmailAddressAsync(model.RepairPeopleSelectedValue); string body = string.Format("<p>{0}</p><br/><br/><p>Incident ID: <span id='x_IncidentID'>{1}</span><br/><br/>Property ID: <span id='x_PropertyID'>{2}</span></p>", incident.sl_dispatcherComments, incident.Id, incident.sl_propertyID.Id ); var attendee = new Graph.Attendee { EmailAddress = new EmailAddress { Address = repairPeople.sl_emailaddress, Name = repairPeople.Title }, Type = AttendeeType.Required, Status = new ResponseStatus() }; var newEvent = new Graph.Event { Subject = "Repair Event", Body = new ItemBody { Content = body, ContentType = BodyType.Html }, ShowAs = FreeBusyStatus.Busy, Start = new DateTimeTimeZone { DateTime = model.TimeSlotsSelectedValue.ToString(), TimeZone = TimeZone.CurrentTimeZone.StandardName }, End = new DateTimeTimeZone { DateTime = (model.TimeSlotsSelectedValue.AddHours(1)).ToString(), TimeZone = TimeZone.CurrentTimeZone.StandardName }, Location = new Location { Address = new PhysicalAddress(), // Coordinates = new outlookGeoCoordinates(), DisplayName = incident.sl_roomID.Title, }, Attendees = new Attendee[] { attendee } }; try { newEvent = await graphService.Me.Events.Request().AddAsync(newEvent); } catch { } }