internal static async void ProcessPostRequests(HttpClient client) { ResponseAlbumModel album = new ResponseAlbumModel { Title = "Xml added", ProducerName = "Xml Produer", Year = 2000 }; var httpResponse = await client.PostAsXmlAsync("api/albums", album); Console.WriteLine(httpResponse.ReasonPhrase.ToString() + " from albums"); }
internal static async void ExecutePostRequests(HttpClient client) { ResponseAlbumModel testAlbum = new ResponseAlbumModel { Title = "Za posleden put fo smeniqm", ProducerName = "Common Productions", Year = 2009 }; ResponseSongModel song = new ResponseSongModel { Title = "EE chovek omruzna mi", Genre = "Bate i na mene spoko", Year = 2015, AlbumId = 4, ArtistId = 24 }; ResponseArtistModel artist = new ResponseArtistModel { Name = "Kaenko Ukolovich", Country = "Ukraine", DataOfBirth = new DateTime(1999, 2, 4) }; var httpResponseAlbum = await client.PostAsJsonAsync("api/albums", testAlbum); var httpResponseSong = await client.PostAsJsonAsync("api/songs", song); var httpResponseArtist = await client.PostAsJsonAsync("api/artists", artist); Console.WriteLine(httpResponseAlbum.ReasonPhrase.ToString() + " from albums"); Console.WriteLine(httpResponseSong.ReasonPhrase.ToString() + " from songs"); Console.WriteLine(httpResponseArtist.ReasonPhrase.ToString() + " from artists"); }
internal static async void ExecutePostRequests(HttpClient client) { ResponseAlbumModel testAlbum = new ResponseAlbumModel { Title = "Za posleden put fo smeniqm", ProducerName = "Common Productions", Year = 2009 }; ResponseSongModel song = new ResponseSongModel { Title = "EE chovek omruzna mi", Genre = "Bate i na mene spoko", Year = 2015, AlbumId = 4, ArtistId = 24 }; ResponseArtistModel artist = new ResponseArtistModel { Name = "Kaenko Ukolovich", Country = "Ukraine", DataOfBirth = new DateTime(1999, 2, 4) }; var httpResponseAlbum = await client.PostAsJsonAsync("api/albums", testAlbum); var httpResponseSong = await client.PostAsJsonAsync("api/songs", song); var httpResponseArtist = await client.PostAsJsonAsync("api/artists", artist); Console.WriteLine(httpResponseAlbum.ReasonPhrase.ToString() + " from albums"); Console.WriteLine(httpResponseSong.ReasonPhrase.ToString() + " from songs"); Console.WriteLine(httpResponseArtist.ReasonPhrase.ToString() + " from artists"); }
public IHttpActionResult Delete(ResponseAlbumModel album) { if (this.data.Albums.All().Any(al => al.Id == album.Id)) { this.data.Albums.Delete(album.Id); int rowsChanged = this.data.SaveChanges(); return(this.Ok($"Rows affected ({rowsChanged})")); } return(this.BadRequest("Album not found!")); }
public IHttpActionResult Delete(ResponseAlbumModel album) { if (this.data.Albums.All().Any(al => al.Id == album.Id)) { this.data.Albums.Delete(album.Id); int rowsChanged = this.data.SaveChanges(); return this.Ok($"Rows affected ({rowsChanged})"); } return this.BadRequest("Album not found!"); }
internal static async void ProcessPostRequests(HttpClient client) { ResponseAlbumModel album = new ResponseAlbumModel { Title = "Xml added", ProducerName = "Xml Produer", Year = 2000 }; var httpResponse = await client.PostAsXmlAsync("api/albums", album); Console.WriteLine(httpResponse.ReasonPhrase.ToString() + " from albums"); }
public IHttpActionResult Post(ResponseAlbumModel album) { if (this.ModelState.IsValid) { //// TODO: Add class model for saving objects. Album albumToAdd = Mapper.Map <Album>(album); //// this is ridiculous ↓ albumToAdd.Producer = album.ProducerName; this.data.Albums.Add(albumToAdd); int rowsChanged = this.data.SaveChanges(); return(this.Ok($"Rows affected ({rowsChanged})")); } return(this.BadRequest(this.ModelState)); }
public IHttpActionResult Post(ResponseAlbumModel album) { if (this.ModelState.IsValid) { //// TODO: Add class model for saving objects. Album albumToAdd = Mapper.Map<Album>(album); //// this is ridiculous ↓ albumToAdd.Producer = album.ProducerName; this.data.Albums.Add(albumToAdd); int rowsChanged = this.data.SaveChanges(); return this.Ok($"Rows affected ({rowsChanged})"); } return this.BadRequest(this.ModelState); }
public IHttpActionResult Put(ResponseAlbumModel album) { if (this.ModelState.IsValid) { Album albumToUpdate = this.data.Albums.GetById(album.Id); if (albumToUpdate == null) { return(this.BadRequest($"No such album with this id: {album.Id}")); } Mapper.DynamicMap(album, albumToUpdate); this.data.Albums.Update(albumToUpdate); int rowsChanged = this.data.SaveChanges(); return(this.Ok($"Rows affected ({rowsChanged})")); } return(this.BadRequest(this.ModelState)); }
public IHttpActionResult Put(ResponseAlbumModel album) { if (this.ModelState.IsValid) { Album albumToUpdate = this.data.Albums.GetById(album.Id); if (albumToUpdate == null) { return this.BadRequest($"No such album with this id: {album.Id}"); } Mapper.DynamicMap(album, albumToUpdate); this.data.Albums.Update(albumToUpdate); int rowsChanged = this.data.SaveChanges(); return this.Ok($"Rows affected ({rowsChanged})"); } return this.BadRequest(this.ModelState); }
internal static void ExecutePutRequests(HttpClient client) { ResponseAlbumModel updateAlbum = new ResponseAlbumModel { Id = 15, Title = "Updated object", ProducerName = "Assert.AreEqual(this.StatusCode, StatusCode.Updated)", Year = 2009 }; ResponseSongModel updateSong = new ResponseSongModel { Id = 32, Title = "Updateed song", Genre = "Genre updated", Year = 2000, AlbumId = 4, ArtistId = 25 }; ResponseArtistModel updateArtist = new ResponseArtistModel { Id = 27, Name = "Updated artist name", Country = "Country Updated", DataOfBirth = new DateTime(1999, 2, 4) }; var messages = new List <HttpResponseMessage> { client.PutAsJsonAsync("api/albums", updateAlbum).Result, client.PutAsJsonAsync("api/songs", updateSong).Result, client.PutAsJsonAsync("api/artists", updateArtist).Result }; foreach (var msg in messages) { Console.WriteLine(msg.ReasonPhrase.ToString()); } }
internal static void ExecutePutRequests(HttpClient client) { ResponseAlbumModel updateAlbum = new ResponseAlbumModel { Id = 15, Title = "Updated object", ProducerName = "Assert.AreEqual(this.StatusCode, StatusCode.Updated)", Year = 2009 }; ResponseSongModel updateSong = new ResponseSongModel { Id = 32, Title = "Updateed song", Genre = "Genre updated", Year = 2000, AlbumId = 4, ArtistId = 25 }; ResponseArtistModel updateArtist = new ResponseArtistModel { Id = 27, Name = "Updated artist name", Country = "Country Updated", DataOfBirth = new DateTime(1999, 2, 4) }; var messages = new List<HttpResponseMessage> { client.PutAsJsonAsync("api/albums", updateAlbum).Result, client.PutAsJsonAsync("api/songs", updateSong).Result, client.PutAsJsonAsync("api/artists", updateArtist).Result }; foreach (var msg in messages) { Console.WriteLine(msg.ReasonPhrase.ToString()); } }