// POST api/Song public HttpResponseMessage PostSong(Song song) { if (ModelState.IsValid) { db.Songs.Add(song); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, song); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = song.SongID })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/Song/5 public HttpResponseMessage PutSong(int id, Song song) { if (ModelState.IsValid && id == song.SongID) { db.Entry(song).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK, song); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }