private async Task <List <DocumentInfo> > GetDocumentsInfo(List <ContentDocument> documents) { var docIds = documents.Select(d => d.Id); var syncInfo = await _syncDataService.GetSyncConfigs(docIds); var contentDistributions = await _contentDistributionDataService.GetAllContentDistributions(); var documentWithSyncVersion = documents.Join(syncInfo, d => d.Id, s => s.TransactionItemType, (d, s) => new { Document = d, Sync = s }).ToList(); return(documentWithSyncVersion .Select(ds => new DocumentInfo(ds.Document, ds.Sync, contentDistributions.FirstOrDefault(cd => cd.ContentVersionId == ds.Document.LatestPublishedVersionId))) .ToList()); }
/// <summary> /// Get new and updated documents /// </summary> private async Task <List <SpotlightItem> > GetNewAndUpdated() { var mobileAppConfigurationId = await _settingsDataService.GetCurrentMobileConfigurationID(); var categoriesInfo = await _categoryInfoDataService.GetCategoryInfos(); var newCategoryContents = await _newCategoryContentDataService.GetCategoryContent(mobileAppConfigurationId); var newCategoriesInfo = categoriesInfo.Where(ci => newCategoryContents.Any(cc => cc.CategoryId == ci.Category.Id)); var lastSyncID = await _syncDataService.GetSyncConfig(SuccessfulSyncState.SyncedObjectMetaType.ContentDocuments.ToString()); var documentsSyncInfo = await _syncDataService.GetSyncConfigs(lastSyncID?.SyncId); var contentDistributions = await _contentDistributionDataService.GetAllContentDistributions(); var contentDocuments = await _contentDocumentDataService.GetContentDocumentsByID(documentsSyncInfo.Select(si => si.TransactionItemType).Union(newCategoryContents.Select(ncc => ncc.ContentId))); var allDocumentsSyncInfo = await _syncDataService.GetSyncConfigs(contentDocuments.Select(cd => cd.Id)); var documentsWithSyncVersion = allDocumentsSyncInfo.Join(contentDocuments, si => si.TransactionItemType, cd => cd.Id, (si, cd) => new { Document = cd, Sync = si }); var documentsInfos = documentsWithSyncVersion.Select(dsc => new DocumentInfo(dsc.Document, dsc.Sync, contentDistributions.FirstOrDefault(cd => cd.ContentVersionId == dsc.Document.LatestPublishedVersionId))); return(documentsInfos.Select(fd => { var categoryInfo = newCategoriesInfo.FirstOrDefault(csi => csi.Documents.Any(d => d.Document.Id == fd.Document.Id)); categoryInfo = categoryInfo ?? categoriesInfo.FirstOrDefault(csi => csi.Documents.Any(d => d.Document.Id == fd.Document.Id)); return new SpotlightItem { Name = fd.Document.Title, Description = fd.Document.Description, Location = categoryInfo != null ? GetLocation(categoryInfo, categoriesInfo) : string.Empty, Media = new MediaLink(fd), AddedOn = fd.Document.PublishedVersionLastModifiedDate, Group = SpotlightGroup.NewAndUpdated, }; }).OrderByDescending(d => d.AddedOn.GetValueOrDefault().DayOfYear).ThenBy(d => d.Name).ToList()); }