public async Task <IActionResult> SaveSong(int userId, int songId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var savedSong = await _repo.GetSavedSong(userId, songId); if (savedSong != null) { return(BadRequest("You already saved this song")); } if (await _repo.GetSong(songId) == null) { return(NotFound()); } savedSong = new SavedSong { UserId = userId, SongId = songId }; _repo.Add <SavedSong>(savedSong); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to save song")); }