public async Task <Response> GetAllUserPlaylists([FromQuery] int songId, [FromQuery] int playlistId) { return(await RequestHandler.ExecuteRequestAsync(async() => { await _playlistService.AddSongToPlaylist(songId, playlistId); })); }
public async Task <PlaylistVM> LoadPlaylistWithSmartSearch(State state, int userId, int maxCount, string playlistName) { try { var count = maxCount; var user = await _identityService.GetFullUser(userId); var songs = await _songService.GetAllSongs(); if (user.Preferences != null && user.Preferences.Count > 0) { var orderedGenrePreferences = user.Preferences.OrderByDescending(x => x.Preference).ToList(); var orderedQuerry = songs.OrderBy(x => x.Genre == orderedGenrePreferences.First().Genre). ThenBy(x => x.Genre = orderedGenrePreferences[1].Genre). ThenBy(x => x.Genre = orderedGenrePreferences[2].Genre). ThenBy(x => x.Genre = orderedGenrePreferences[3].Genre). ThenBy(x => x.Genre = orderedGenrePreferences[4].Genre); //for (int i = 1; i < orderedGenrePreferences.Count; i++) //{ // //orderedQuerry = orderedQuerry.ThenBy(x => x.Genre == orderedGenrePreferences[i].Genre); //} try { songs = orderedQuerry.ToList(); } catch (Exception e) { } } var result = new List <Song>(); for (int i = 0; i <= 4; i++) { var fPrioritySongs = GetSongsBySearchPriority(songs, state, (SmartSearchPriority)i).ToList(); count -= fPrioritySongs.Except(result).Count(); result.AddRange(fPrioritySongs.Except(result)); if (count <= 0) { break; } } var playlist = new Playlist() { Name = playlistName }; playlist = await _playlistService.CreatePlaylistWithReturn(playlist, user.ID); foreach (var song in result) { await _playlistService.AddSongToPlaylist(song.ID, playlist.ID); } var playlistToReturn = new PlaylistVM() { Name = playlist.Name, ID = playlist.ID, Songs = new List <SongVM>() }; foreach (var song in result.Take(maxCount).ToList()) { playlistToReturn.Songs.Add(new SongVM() { Name = song.Name, Band = song.Band, State = song.State, Genre = song.Genre }); } return(playlistToReturn); } catch (Exception e) { } throw new NotImplementedException(); }