public IHttpActionResult Update(int id, SongModel song) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var existingSong = this.data.Songs.Find(id); if (existingSong == null) { return BadRequest(NoSuchSongId); } existingSong.Title = song.Title; existingSong.Year = song.Year; existingSong.Genre = song.Genre; existingSong.AlbumId = song.AlbumId; existingSong.ArtistId = song.ArtistId; this.data.SaveChanges(); song.SongId = existingSong.Id; return Ok(song); }
public IHttpActionResult Create(SongModel song) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var newSong = new Song { Title = song.Title, Year = song.Year, Genre = song.Genre, AlbumId = song.AlbumId, ArtistId = song.ArtistId }; this.data.Songs.Add(newSong); this.data.SaveChanges(); song.SongId = newSong.Id; return Ok(song); }