public async Task <DashboardInspectionDetailsViewModel> GetDashboardInspectionDetailsViewModelAsync(Graph.GraphService graphService, OneNoteServiceFactory oneNoteServiceFactory, int incidentId, string CurrentUser)
        {
            Task <Graph.IUser[]> getRepairPeople = null;
            Task <RepairPhoto[]> getRepairPhotos = null;

            var videos = 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          = GetInspectionByIdAsync(inspectionID);
            var getInspectionPhotos = GetInspectionPhotosAsync(inspectionID);

            var incidentStatus = incident.sl_status;

            if (incidentStatus == "Pending Assignment")
            {
                getRepairPeople = graphService.GetGroupMembersAsync("Repair People");
            }
            if (incidentStatus == "Repair Pending Approval" || incidentStatus == "Repair Approved")
            {
                getRepairPhotos = GetRepairPhotosAsync(incidentId);
            }

            var unifiedGroupFetcher = graphService.groups.GetById(property.sl_group);
            var unifiedGroup        = unifiedGroupFetcher.ExecuteAsync();
            var groupFiles          = GetGroupFilesAsync(unifiedGroupFetcher, (await unifiedGroup).mailNickname);
            var groupConversations  = GetConversationsAsync(unifiedGroupFetcher, (await unifiedGroup).mail);

            var notebookName   = (await unifiedGroup).displayName + " Notebook";;
            var oneNoteService = oneNoteServiceFactory.CreateOneNoteServiceForUnifiedGroup(await unifiedGroup);
            var notebook       = GetOrCreateNoteBook(await oneNoteService, notebookName);
            var pages          = (await notebook) != null
                ? GetOneNotePagesAsync(await oneNoteService, (await notebook).Id, property.Title, incidentId)
                : Task.FromResult(new HyperLink[0]);

            // Repair people are included in property group.
            // Before we get members of a group, we must make sure that repair people have been retrieved.
            // Otherwise, we'll get an error:
            //         The context is already tracking a different entity with the same resource Uri.
            if (getRepairPeople != null)
            {
                await getRepairPeople;
            }
            var groupMembers = graphService.GetGroupMembersAsync(unifiedGroupFetcher);

            var recentEarliestDateTime = new DateTimeOffset(DateTime.UtcNow).AddDays(-7);
            var recentDocuments        = (await groupFiles)
                                         .Where(i => i.dateTimeLastModified > recentEarliestDateTime)
                                         .ToList();

            property.propertyImgUrl = await propertyImgUrl;

            var isCurrentUserDispatcher = CurrentUser == AppSettings.DispatcherEmail;


            var viewModel = new DashboardInspectionDetailsViewModel
            {
                viewName             = IncidentStatusViewMappings[incidentStatus],
                PropertyDetail       = property,
                incidentId           = incidentId,
                incident             = incident,
                UnifiedGroupNickName = (await unifiedGroup).mailNickname,
                UnifiedGroupId       = (await unifiedGroup).objectId,
                UnifiedGroupEmail    = (await unifiedGroup).mail,
                inspection           = await inspection,
                videos = await videos,
                files  = (await groupFiles)
                         .Select(i => HyperLink.Create(i.name, i.webUrl))
                         .ToArray(),
                recentDocuments = recentDocuments
                                  .Select(i => HyperLink.Create(i.name, i.webUrl))
                                  .ToArray(),
                members = await groupMembers,
                roomInspectionPhotos = await getInspectionPhotos,
                inspectionComment    = await GetInspectionCommentAsync(inspectionID, incident.sl_roomID.Id),
                //tasks = await GetTaskHyperLinksAsync(unifiedGroup)
                repairPeople    = getRepairPeople != null ? await getRepairPeople : new Graph.IUser[0],
                repairPhotos    = getRepairPhotos != null ? await getRepairPhotos : new RepairPhoto[0],
                DispatcherMails = isCurrentUserDispatcher ? await GetMailsForDispatcherAsync(graphService, CurrentUser) : new HyperLink[0],
                oneNoteUrl      = (await notebook) != null ? (await notebook).Url : "",
                oneNotePages    = await pages,
                conversations   = await groupConversations
            };

            return(viewModel);
        }
Exemple #2
0
        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);
        }