예제 #1
0
 public IActionResult UpdatePlaylist(int id, [FromBody] PlaylistForUpdateDto playlist)
 {
     try
     {
         if (playlist == null)
         {
             _logger.LogError("Playlist object sent from client is null.");
             return(BadRequest("Playlist object is null"));
         }
         if (!ModelState.IsValid)
         {
             _logger.LogError("Invalid playlist object sent from client");
             return(BadRequest("Invalid model object"));
         }
         var playlistEntity = _repoWrapper.Playlist.GetPlaylistById(id);
         if (playlistEntity == null)
         {
             _logger.LogError($"Playlist with id: {id}, hasn't been found in db.");
             return(NotFound());
         }
         _mapper.Map(playlist, playlistEntity);
         _repoWrapper.Playlist.UpdatePlaylist(playlistEntity);
         _repoWrapper.Save();
         return(NoContent());
     }
     catch (Exception ex)
     {
         _logger.LogError($"Something went wrong inside UpdatePlaylist action: {ex.Message}");
         return(StatusCode(500, "Internal server error"));
     }
 }
예제 #2
0
        public async Task <IActionResult> UpdatePlaylist([FromRoute] int id, [FromBody] PlaylistForUpdateDto playlistForUpdateDto)
        {
            var playlistFromRepo = await _repo.GetPlaylist(id);

            _mapper.Map(playlistForUpdateDto, playlistFromRepo);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            throw new Exception($"Error when updated {id}");
        }