public RelatedSongsContract GetRelatedSongs(int songId, SongOptionalFields fields, ContentLanguagePreference?lang = null) { var language = lang ?? permissionContext.LanguagePreference; return(repository.HandleQuery(ctx => { var song = ctx.Load(songId); var songs = new RelatedSongsQuery(ctx).GetRelatedSongs(song); return new RelatedSongsContract { ArtistMatches = songs.ArtistMatches .Select(a => new SongForApiContract(a, null, language, fields)) .OrderBy(a => a.Name) .ToArray(), LikeMatches = songs.LikeMatches .Select(a => new SongForApiContract(a, null, language, fields)) .OrderBy(a => a.Name) .ToArray(), TagMatches = songs.TagMatches .Select(a => new SongForApiContract(a, null, language, fields)) .OrderBy(a => a.Name) .ToArray() }; })); }
private Song[] GetSongSuggestions(IDatabaseContext <Song> ctx, Song song) { var cacheKey = string.Format("GetSongSuggestions.{0}", song.Id); var songIds = cache.GetOrInsert(cacheKey, CachePolicy.AbsoluteExpiration(24), () => { var related = new RelatedSongsQuery(ctx).GetLikeMatches(song, new[] { song.Id }, 4); return(related); }); if (!songIds.Any()) { return(new Song[0]); } return(ctx.Query() .Where(s => songIds.Contains(s.Id)) .ToArray()); }
public RelatedSongsContract GetRelatedSongs(int songId) { return(repository.HandleQuery(ctx => { var song = ctx.Load(songId); var songs = new RelatedSongsQuery(ctx).GetRelatedSongs(song); return new RelatedSongsContract { ArtistMatches = songs.ArtistMatches .Select(a => new SongContract(a, permissionContext.LanguagePreference)) .OrderBy(a => a.Name) .ToArray(), LikeMatches = songs.LikeMatches .Select(a => new SongContract(a, permissionContext.LanguagePreference)) .OrderBy(a => a.Name) .ToArray(), TagMatches = songs.TagMatches .Select(a => new SongContract(a, permissionContext.LanguagePreference)) .OrderBy(a => a.Name) .ToArray() }; })); }