// POST api/Songs public HttpResponseMessage PostSong(SongModel song) { if (song == null) { var errResponse = this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Song should be not null!"); return errResponse; } Song songToAdd = song.ToSong(); var entity = this.repository.Add(songToAdd); var response = this.Request.CreateResponse(HttpStatusCode.Created, entity); response.Headers.Location = new Uri(this.Request.RequestUri + song.SongId.ToString(CultureInfo.InvariantCulture)); return response; }
public static Song Add(SongModel song) { HttpResponseMessage responseMessage = client.PostAsXmlAsync("api/songs", song).Result; var mySong = responseMessage.Content.ReadAsAsync<Song>().Result; if (responseMessage.IsSuccessStatusCode) { Console.WriteLine("Song added: {0}", song.Title); } else { Console.WriteLine("{0} ({1})", (int)responseMessage.StatusCode, responseMessage.ReasonPhrase); } return mySong; }