private static void UpdateSong() { Console.Write("Title: "); string title = Console.ReadLine(); Console.Write("Year: "); int year = int.Parse(Console.ReadLine()); Console.Write("Genre: "); string genre = Console.ReadLine(); Console.Write("AlbumId: "); int albumId = int.Parse(Console.ReadLine()); Console.Write("ArtistId: "); int artistId = int.Parse(Console.ReadLine()); Song updatedSong = new Song() { Title = title, Year = year, Genre = genre, AlbumId = albumId, ArtistId = artistId }; Console.Write("Id to update: "); int idForUpdate = int.Parse(Console.ReadLine()); var putSongResponse = jsonClient.PutAsJsonAsync("api/songs/" + idForUpdate, updatedSong).Result; if (putSongResponse.IsSuccessStatusCode) { Console.WriteLine("Song updated!"); } else { Console.WriteLine("{0}, ({1})", (int)putSongResponse.StatusCode, putSongResponse.ReasonPhrase); } }
private static void CreateSong() { Console.Write("Title: "); string title = Console.ReadLine(); Console.Write("Year: "); int year = int.Parse(Console.ReadLine()); Console.Write("Genre: "); string genre = Console.ReadLine(); Console.Write("AlbumId: "); int albumId = int.Parse(Console.ReadLine()); Console.Write("ArtistId: "); int artistId = int.Parse(Console.ReadLine()); Song song = new Song() { Title = title, Year = year, Genre = genre, AlbumId = albumId, ArtistId = artistId }; var postSongResponse = jsonClient.PostAsJsonAsync("api/songs", song).Result; if (postSongResponse.IsSuccessStatusCode) { Console.WriteLine("Song added!"); } else { Console.WriteLine("{0} ({1})", (int)postSongResponse.StatusCode, postSongResponse.ReasonPhrase); } }