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()); }
public async Task <MobileConfigurationDTO> GetCurrentMobileConfiguration() { var currentMCID = await _settingsDataService.GetCurrentMobileConfigurationID(); var mobileApp = await _mobileAppConfigDataService.GetMobileAppConfig(currentMCID); if (mobileApp == null) { return(GetDefaultMobileConfiguration()); } var categoryInfos = await _categoryInfoDataService.GetCategoryInfos(); var topCategories = categoryInfos.Where(ci => ci.Category.IsTopLevel.HasValue && ci.Category.IsTopLevel.Value); var attachments = await GetAttachments(mobileApp, categoryInfos); var syncInfo = await _syncDataService.GetSyncConfigs(attachments.Select(at => at.Id)); var attSyncDictionary = attachments.Join(syncInfo, at => at.Id, si => si.TransactionItemType, (at, si) => new { AttachementId = at.Id, SyncId = si.SyncId }).ToDictionary(i => i.AttachementId, i => i.SyncId); Func <string, string> getSyncId = id => { return(string.IsNullOrWhiteSpace(id) == false && attSyncDictionary.Keys.Contains(id) ? attSyncDictionary[id] : string.Empty); }; Func <string, string> getImage = id => { var att = attachments.FirstOrDefault(a => a.Id == id); return(att == null ? string.Empty : ImageUtil.GetPathFromAttachment(att.Id, getSyncId(id), att.Name)); }; return(new MobileConfigurationDTO() { Name = mobileApp.Title, LandscapeBackgroundImage = getImage(mobileApp.LandscapeAttachmentId), PortraitBackgroundImage = getImage(mobileApp.PortraitAttachmentId), LogoImage = getImage(mobileApp.LogoAttachmentId), ButtonConfiguration = GetButtonConfiguration(mobileApp, getImage), Buttons = topCategories.Select(ci => new ButtonDTO(ci)).ToList(), TopCategories = GetCategories(topCategories, categoryInfos, getImage), ReportProblemEmail = mobileApp.ReportAnIssue }); }