public IActionResult UpdateSong(Guid songId, [FromBody] SongForUpdate songForUpdate) { if (songForUpdate == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var song = _sprotifyRepository.GetSong(songId); if (song == null) { return(NotFound()); } Mapper.Map(songForUpdate, song); _sprotifyRepository.UpdateSong(song); if (!_sprotifyRepository.Save()) { throw new Exception($"Updating song {songId} failed."); } return(NoContent()); }
public async Task <IActionResult> UpdateSong(SongForUpdate songForUpdate) { var currentSong = await _playAppRepository.GetSong(songForUpdate.Id); _mapper.Map(songForUpdate, currentSong); if (await _playAppRepository.SaveAll()) { return(Ok(new { data = currentSong })); } return(BadRequest(new { message = "Song was not updated" })); }