private static void AddArtist(Artist artist) { HttpResponseMessage response = client.PostAsJsonAsync("Artists", artist).Result; if (response.IsSuccessStatusCode) { Console.WriteLine("Artist added!"); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } }
public IHttpActionResult Create(ArtistModel artist) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var newArtist = new Artist { Name = artist.Name }; this.data.Artists.Add(newArtist); this.data.SaveChanges(); artist.Id = newArtist.Id; return Ok(artist); }
public void AddArtist(Artist artist) { Artists.Add(artist); }
private static void UpdateArtist(int id, Artist artist) { string url = "Artists/" + id; HttpResponseMessage response = client.PutAsJsonAsync(url, artist).Result; if (response.IsSuccessStatusCode) { Console.WriteLine("Artist with id {0} changed", id); } else { Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase); } }
static void Main() { // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); Album album = new Album { Title = "Album title 7", Year = "2000", Producer = "Producer 7" }; AddAlbum(album); Console.WriteLine("Show all albums:"); foreach (var a in GetAlbums()) { Console.WriteLine("{0} {1} {2} {3}", a.AlbumId, a.Title, a.Year, a.Producer); } Console.WriteLine("Show album:"); var currentAlbum = GetAlbum(3); Console.WriteLine("{0} {1} {2} {3}", currentAlbum.AlbumId, currentAlbum.Title, currentAlbum.Year, currentAlbum.Producer); DeleteAlbum(8); DeleteAlbum(7); DeleteAlbum(6); Console.WriteLine("Update album:"); Album albumUpdated = new Album { AlbumId = 5, Title = "Album title 7", Year = "2000", Producer = "Producer 7" }; UpdateAlbum(5, albumUpdated); Artist artist = new Artist { Name = "Name3", Country = "Country3", DateOfBirth = DateTime.Parse("30/05/1988"), }; AddArtist(artist); Console.WriteLine("Show all artists:"); foreach (var ar in GetArtists()) { Console.WriteLine("{0} {1} {2} {3}", ar.ArtistId, ar.Name, ar.Country, ar.DateOfBirth); } Console.WriteLine("Show artist:"); var currentArtist = GetArtist(2); Console.WriteLine("{0} {1} {2} {3}", currentArtist.ArtistId, currentArtist.Name, currentArtist.Country, currentArtist.DateOfBirth); Console.WriteLine("Update album:"); var artistUpdate = new Artist { ArtistId = 2, Name = "Name22", Country = "Country22", DateOfBirth = DateTime.Parse("30/05/1988"), }; UpdateArtist(2, artistUpdate); DeleteArtist(1); Song song = new Song { Title = "Song55", Genre = "mixed", Year = "2014", AlbumId = 4, ArtistId = 3 }; AddSong(song); Console.WriteLine("Show all songs:"); foreach (var s in GetSongs()) { Console.WriteLine("{0} {1} {2} {3} {4} {5}", s.SongId, s.Title, s.Genre, s.Year, s.Album.Title, s.Artist.Name); } Console.WriteLine("Show song:"); var currentSong = GetSong(3); Console.WriteLine("{0} {1} {2} {3} {4} {5}", currentSong.SongId, currentSong.Title, currentSong.Genre, currentSong.Year, currentSong.Album.Title, currentSong.Artist.Name); Console.WriteLine("Update song:"); Song songUpdated = new Song { SongId = 4, Title = "Song10", Genre = "mixed", Year = "2014", AlbumId = 4, ArtistId = 3 }; UpdateSong(4, songUpdated); DeleteSong(5); //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); }