public IHttpActionResult Add(SongModel songModel) { if (!this.ModelState.IsValid) { return(BadRequest(ModelState)); } var newAtist = SongModel.ToSong(songModel); this.data.Songs.Add(newAtist); this.data.SaveChanges(); songModel.ID = newAtist.ID; return(Ok(songModel)); }
// 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 IHttpActionResult Update(int id, SongModel songModel) { if (!this.ModelState.IsValid) { return(BadRequest(ModelState)); } var existingSong = this.data.Songs.Get(id); if (existingSong == null) { return(BadRequest(BabRequestMessage)); } SongModel.ToSong(songModel, existingSong); this.data.Songs.Update(existingSong); this.data.SaveChanges(); return(Ok(songModel)); }