// POST api/Albums public HttpResponseMessage PostAlbum(AlbumModel album) { if (album == null) { var errResponse = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error!"); return errResponse; } Album albumToAdd = album.ToAlbum(); var entity = this.repository.Add(albumToAdd); var response = this.Request.CreateResponse(HttpStatusCode.Created, entity); response.Headers.Location = new Uri(this.Request.RequestUri + album.AlbumId.ToString(CultureInfo.InvariantCulture)); return response; }
public static Album Add(AlbumModel album) { HttpResponseMessage responseMessage = client.PostAsXmlAsync("api/albums", album).Result; var myAlbum = responseMessage.Content.ReadAsAsync<Album>().Result; if (responseMessage.IsSuccessStatusCode) { Console.WriteLine("Album added: {0}", album.Title); } else { Console.WriteLine("{0} ({1})", (int)responseMessage.StatusCode, responseMessage.ReasonPhrase); } return myAlbum; }