public IHttpActionResult Put(SongDetailAndEdit song) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateSongService(); if (!service.UpdateSong(song)) { return(InternalServerError()); } return(Ok()); }
public bool UpdateSong(SongDetailAndEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .Songs .Single(e => e.SongId == model.SongID && e.OwnerId == _userId); entity.Title = model.Title; entity.Length = model.Length; entity.AlbumId = model.AlbumId; entity.GenreId = model.GenreId; return(ctx.SaveChanges() == 1); } }