public IActionResult UpdateSong(Guid playlistId, Guid songId, [FromBody] MoveSongInPlaylist moveSongInPlaylist) { if (moveSongInPlaylist == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } if (!_sprotifyRepository.PlaylistExists(playlistId)) { return(NotFound()); } var song = _sprotifyRepository.GetSongFromPlaylist(playlistId, songId); if (song == null) { return(NotFound()); } if (moveSongInPlaylist.OldIndex == moveSongInPlaylist.NewIndex) { return(NoContent()); } _sprotifyRepository.UpdateSongInPlaylist(playlistId, songId, moveSongInPlaylist.OldIndex, moveSongInPlaylist.NewIndex); if (!_sprotifyRepository.Save()) { throw new Exception($"Updating song {songId} from playlist {playlistId} failed."); } return(NoContent()); }