public async Task <TelevisionEpisodeCardResultsViewModel> Handle( QuerySearchIndexEpisodes request, CancellationToken cancellationToken) { SearchResult searchResult = await _searchIndex.Search( request.Query, (request.PageNumber - 1) *request.PageSize, request.PageSize); Option <JellyfinMediaSource> maybeJellyfin = await _mediaSourceRepository.GetAllJellyfin() .Map(list => list.HeadOrNone()); Option <EmbyMediaSource> maybeEmby = await _mediaSourceRepository.GetAllEmby() .Map(list => list.HeadOrNone()); List <EpisodeMetadata> episodes = await _televisionRepository .GetEpisodesForCards(searchResult.Items.Map(i => i.Id).ToList()); var items = new List <TelevisionEpisodeCardViewModel>(); foreach (EpisodeMetadata episodeMetadata in episodes) { string localPath = await episodeMetadata.Episode.GetLocalPath( _plexPathReplacementService, _jellyfinPathReplacementService, _embyPathReplacementService, false); items.Add(ProjectToViewModel(episodeMetadata, maybeJellyfin, maybeEmby, true, localPath)); } return(new TelevisionEpisodeCardResultsViewModel(searchResult.TotalCount, items, searchResult.PageMap)); }