public async Task CreateUnifiedGroupsForPropertiesAsync(GraphServiceClient graphService, string graphAccessToken) { var properties = Task.Run(() => CSOMUtil.GetListItems(clientContext, "Properties")); var members = new List <Graph.User>(); { var queryUsers = (await graphService.Users.Request().Filter(string.Format("mail eq '{0}'", AppSettings.DispatcherEmail)).GetAsync()).CurrentPage; var dispatcher = queryUsers.Count > 0 ? queryUsers[0]: null; if (dispatcher == null) { return; } var inspectors = await graphService.GetGroupMembersAsync("Inspectors"); var repairPeople = await graphService.GetGroupMembersAsync("Repair People"); if (dispatcher != null) { members.Add(dispatcher); } members.AddRange(inspectors); members.AddRange(repairPeople); } foreach (var property in await properties) { var group = await graphService.GetGroupByDisplayNameAsync((string)property["Title"]); if (group == null) { group = await CreateUnifiedGroupForPropertyAsync(graphService, graphAccessToken, property, members); } property["sl_group"] = group.Id; property.Update(); } clientContext.ExecuteQuery(); await UpdateGroupPhotoAsync(graphService); }
public async Task <AddInspectorViewModel> GetDashboardAddInspectorViewModelAsync(GraphServiceClient graphService) { AddInspectorViewModel viewModel = new AddInspectorViewModel(); viewModel.Candidates = new List <InspectorViewModel>(); IEnumerable <User> inspectors = await graphService.GetGroupMembersAsync("Inspectors"); IEnumerable <User> allUsers = await graphService.Users.Request().GetAllAsync(); var nonInspectors = allUsers.Except(inspectors, new UserComparerbyId()); viewModel.Candidates.AddRange(nonInspectors.Select(i => new InspectorViewModel { DisplayName = i.DisplayName, Id = i.Id, PrincipalName = i.UserPrincipalName })); return(viewModel); }
public async Task <DashboardInspectionDetailsViewModel> GetDashboardInspectionDetailsViewModelAsync(GraphServiceClient graphService, int incidentId, string CurrentUser) { Graph.User[] getRepairPeople = null; Task <RepairPhoto[]> getRepairPhotos = null; var videos = await GetVideosAsync(AppSettings.VideoPortalIncidentsChannelName, incidentId); var incident = await GetIncidentByIdAsync(incidentId); if (incident.sl_inspectionIDId == null) { return(null); } var property = incident.sl_propertyID; var propertyImgUrl = GetPropertyPhotoAsync(property.Id); var inspectionID = incident.sl_inspectionIDId.Value; var inspection = await GetInspectionByIdAsync(inspectionID); var getInspectionPhotos = await GetInspectionPhotosAsync(inspectionID); var incidentStatus = incident.sl_status; if (incidentStatus == "Pending Assignment") { getRepairPeople = await graphService.GetGroupMembersAsync("Repair People"); } if (incidentStatus == "Repair Pending Approval" || incidentStatus == "Repair Approved") { getRepairPhotos = GetRepairPhotosAsync(incidentId); } var unifiedGroupFetcher = graphService.Groups[property.sl_group]; var unifiedGroup = await unifiedGroupFetcher.Request().GetAsync(); var groupFiles = await GetGroupFilesAsync(unifiedGroupFetcher); var groupConversations = await GetConversationsAsync(unifiedGroupFetcher, unifiedGroup.Mail); var propertyExcelWorkbook = await ExcelService.GetPropertyExcelWorkbooksAsync(property.sl_group); var notebook = await OneNoteService.GetNoteBookByNameAsync(unifiedGroup, unifiedGroup.DisplayName + " Notebook"); var oneNotePages = (notebook != null) ? await Services.OneNoteService.GetOneNotePagesAsync(graphService, unifiedGroup) : await Task.FromResult(new HyperLink[0]); var groupMembers = await graphService.GetGroupMembersAsync(unifiedGroupFetcher); var plan = await PlanService.GetPlanAsync(unifiedGroup); List <O365Task> tasks = new List <O365Task>(); if (plan != null) { tasks = await GetO365TasksAsync(graphService, plan); } var recentEarliestDateTime = new DateTimeOffset(DateTime.UtcNow).AddDays(-7); var recentDocuments = groupFiles .Where(i => i.dateTimeLastModified > recentEarliestDateTime) .ToList(); property.propertyImgUrl = await propertyImgUrl; var isCurrentUserDispatcher = CurrentUser == AppSettings.DispatcherEmail; var bannotateImage = true; if (notebook == null || string.IsNullOrEmpty(notebook.oneNoteWebUrl) || oneNotePages.Where(x => x.Title.ToString().Equals(string.Format("Incident[{0}]", incidentId))).Count() > 0) { bannotateImage = false; } var viewModel = new DashboardInspectionDetailsViewModel { viewName = IncidentStatusViewMappings[incidentStatus], PropertyDetail = property, incidentId = incidentId, incident = incident, UnifiedGroupNickName = unifiedGroup.MailNickname, UnifiedGroupId = unifiedGroup.Id, UnifiedGroupEmail = unifiedGroup.Mail, inspection = inspection, videos = videos, files = groupFiles .Select(i => HyperLink.Create(i.name, i.webUrl, i.id)) .ToArray(), recentDocuments = recentDocuments .Select(i => HyperLink.Create(i.name, i.webUrl, i.id)) .ToArray(), members = groupMembers, roomInspectionPhotos = getInspectionPhotos, inspectionComment = await GetInspectionCommentAsync(inspectionID, incident.sl_roomID.Id), tasks = tasks.ToArray(), repairPeople = getRepairPeople != null ? getRepairPeople : new Graph.User[0], repairPhotos = getRepairPhotos != null ? await getRepairPhotos : new RepairPhoto[0], DispatcherMails = isCurrentUserDispatcher ? await GetMailsForDispatcherAsync(graphService, CurrentUser) : new HyperLink[0], oneNotePages = oneNotePages, oneNoteUrl = notebook != null ? notebook.oneNoteWebUrl: "", conversations = groupConversations, PlanId = plan != null ? plan.id : string.Empty, PropertyExcelWorkbook = propertyExcelWorkbook, bAnnotateImage = bannotateImage }; return(viewModel); }
public async Task CreateUnifiedGroupsForPropertiesAsync(GraphServiceClient graphService, string graphAccessToken) { var properties = Task.Run(() => CSOMUtil.GetListItems(clientContext, "Properties")); var members = new List<Graph.User>(); { var queryUsers = (await graphService.Users.Request().Filter(string.Format("mail eq '{0}'", AppSettings.DispatcherEmail)).GetAsync()).CurrentPage; var dispatcher = queryUsers.Count>0 ? queryUsers[0]: null; if (dispatcher == null) return; var inspectors = await graphService.GetGroupMembersAsync("Inspectors"); var repairPeople = await graphService.GetGroupMembersAsync("Repair People"); if (dispatcher != null) members.Add(dispatcher); members.AddRange(inspectors); members.AddRange(repairPeople); } foreach (var property in await properties) { var group = await graphService.GetGroupByDisplayNameAsync((string)property["Title"]); if (group == null) { group = await CreateUnifiedGroupForPropertyAsync(graphService, graphAccessToken, property, members); } property["sl_group"] = group.Id; property.Update(); } clientContext.ExecuteQuery(); await UpdateGroupPhotoAsync(graphService); }
public async Task<DashboardInspectionDetailsViewModel> GetDashboardInspectionDetailsViewModelAsync(GraphServiceClient graphService, int incidentId, string CurrentUser) { Graph.User[] getRepairPeople = null; Task<RepairPhoto[]> getRepairPhotos = null; var videos = await GetVideosAsync(AppSettings.VideoPortalIncidentsChannelName, incidentId); var incident = await GetIncidentByIdAsync(incidentId); if (incident.sl_inspectionIDId == null) return null; var property = incident.sl_propertyID; var propertyImgUrl = GetPropertyPhotoAsync(property.Id); var inspectionID = incident.sl_inspectionIDId.Value; var inspection = await GetInspectionByIdAsync(inspectionID); var getInspectionPhotos = await GetInspectionPhotosAsync(inspectionID); var incidentStatus = incident.sl_status; if (incidentStatus == "Pending Assignment") { getRepairPeople = await graphService.GetGroupMembersAsync("Repair People"); } if (incidentStatus == "Repair Pending Approval" || incidentStatus == "Repair Approved") getRepairPhotos = GetRepairPhotosAsync(incidentId); var unifiedGroupFetcher = graphService.Groups[property.sl_group]; var unifiedGroup = await unifiedGroupFetcher.Request().GetAsync(); var groupFiles = await GetGroupFilesAsync(unifiedGroupFetcher); var groupConversations = await GetConversationsAsync(unifiedGroupFetcher, unifiedGroup.Mail); var propertyExcelWorkbook = await ExcelService.GetPropertyExcelWorkbooksAsync(property.sl_group); var notebook = await OneNoteService.GetNoteBookByNameAsync(unifiedGroup, unifiedGroup.DisplayName + " Notebook"); var oneNotePages = (notebook != null) ? await Services.OneNoteService.GetOneNotePagesAsync(graphService, unifiedGroup) : await Task.FromResult(new HyperLink[0]); var groupMembers = await graphService.GetGroupMembersAsync(unifiedGroupFetcher); var plan = await PlanService.GetPlanAsync(unifiedGroup); List<O365Task> tasks = new List<O365Task>(); if (plan != null) { tasks = await GetO365TasksAsync(graphService, plan); } var recentEarliestDateTime = new DateTimeOffset(DateTime.UtcNow).AddDays(-7); var recentDocuments = groupFiles .Where(i => i.dateTimeLastModified > recentEarliestDateTime) .ToList(); property.propertyImgUrl = await propertyImgUrl; var isCurrentUserDispatcher = CurrentUser == AppSettings.DispatcherEmail; var bannotateImage = true; if (notebook == null || string.IsNullOrEmpty(notebook.oneNoteWebUrl)|| oneNotePages.Where(x => x.Title.ToString().Equals(string.Format("Incident[{0}]", incidentId))).Count() > 0) { bannotateImage = false; } var viewModel = new DashboardInspectionDetailsViewModel { viewName = IncidentStatusViewMappings[incidentStatus], PropertyDetail = property, incidentId = incidentId, incident = incident, UnifiedGroupNickName = unifiedGroup.MailNickname, UnifiedGroupId = unifiedGroup.Id, UnifiedGroupEmail = unifiedGroup.Mail, inspection = inspection, videos = videos, files = groupFiles .Select(i => HyperLink.Create(i.name, i.webUrl, i.id)) .ToArray(), recentDocuments = recentDocuments .Select(i => HyperLink.Create(i.name, i.webUrl, i.id)) .ToArray(), members = groupMembers, roomInspectionPhotos = getInspectionPhotos, inspectionComment = await GetInspectionCommentAsync(inspectionID, incident.sl_roomID.Id), tasks = tasks.ToArray(), repairPeople = getRepairPeople != null ? getRepairPeople : new Graph.User[0], repairPhotos = getRepairPhotos != null ? await getRepairPhotos : new RepairPhoto[0], DispatcherMails = isCurrentUserDispatcher ? await GetMailsForDispatcherAsync(graphService, CurrentUser) : new HyperLink[0], oneNotePages = oneNotePages, oneNoteUrl = notebook != null ? notebook.oneNoteWebUrl: "", conversations = groupConversations, PlanId = plan != null ? plan.id : string.Empty, PropertyExcelWorkbook = propertyExcelWorkbook, bAnnotateImage = bannotateImage }; return viewModel; }