/// <summary> /// Adds new account songs. /// </summary> /// <param name="fileRoutes">Files to add</param> /// <param name="onSuccess">On success</param> /// <param name="onFailure">On failure</param> /// <param name="onError">On error</param> public void AddAccountSongs(string[] fileRoutes, Action onSuccess, Action <NetworkResponse> onFailure, Action onError) { RestSharpTools.PostMultimediaAsync <AccountSong>( "/account/" + AccountId + "/accountsongs", null, fileRoutes, AccountSong.JSON_EQUIVALENTS, (response) => { this.AccountSongs = this.AccountSongs.Union(response.Model).ToList(); onSuccess?.Invoke(); }, onFailure, () => { Console.WriteLine("Exception@Account->AddAccountSongs()"); onError?.Invoke(); } ); }
/// <summary> /// Creates this album with its songs. /// </summary> /// <param name="onSuccess">On success</param> /// <param name="onFailure">On failure</param> /// <param name="onError">On error</param> public void Save(Action onSuccess, Action <NetworkResponse> onFailure, Action onError) { string[] filesRoutes = new string[Songs.Count]; for (int i = 0; i < Songs.Count; i++) { filesRoutes[i] = Songs.ElementAt(i).SongLocation; } RestSharpTools.PostMultimediaAsync <Song>("album/songs", null, filesRoutes, Song.JSON_MIN_EQUIVALENTS, (responseSongs) => { filesRoutes = new string[] { ImageLocation }; RestSharpTools.PostMultimediaAsync <Album>("album/image", null, filesRoutes, JSON_IMAGE_EQUIVALENT, (responseImage) => { List <object> artistsId = new List <object>(); foreach (Artist artist in Artists) { artistsId.Add(new { artist_id = artist.ArtistId }); } List <object> newSongs = new List <object>(); int i = 0; foreach (Song song in Songs) { List <object> songArtistsId = new List <object>(); foreach (Artist artist in song.Artists) { songArtistsId.Add(new { artist_id = artist.ArtistId }); } newSongs.Add(new { genre_id = song.GenreId, title = song.Title, duration = responseSongs.Model.ElementAt(i).Duration, song_location = responseSongs.Model.ElementAt(i).SongLocation, artists_id = songArtistsId }); i++; } var albumData = new { type = Type, name = Name, launch_year = LaunchYear, discography = Discography, image_location = responseImage.Model.ElementAt(0).ImageLocation, artists_id = artistsId, new_songs = newSongs }; RestSharpTools.PostAsync("/album", albumData, (responseAlbum) => { onSuccess(); }, onFailure, () => { Console.WriteLine("Exception@Album->Save()"); onError?.Invoke(); }); }, onFailure, () => { Console.WriteLine("Exception@Album->Save()"); onError?.Invoke(); }); }, onFailure, () => { Console.WriteLine("Exception@Album->Save()"); onError?.Invoke(); }); }