public IActionResult Put(int idAlbum, int id, [FromBody] Models.Request.MusicaDto musicaRequest) { if (albumRepository.Obter(idAlbum) == null) { return(NotFound()); } if (musicaRepository.Obter(id) == null) { return(NotFound()); } var musica = MapearDtoParaDominio(musicaRequest); var mensagens = musicaService.Validar(musica); if (mensagens.Count > 0) { return(BadRequest(mensagens)); } musicaRepository.AtualizarMusica(idAlbum, id, musica); database.Commit(); return(Ok()); }
public IActionResult Put(int idAlbum, int id, [FromBody] Models.Request.MusicaDto musicaRequest) { var album = albumRepository.Obter(idAlbum); if (album == null) { return(NotFound()); } var musica = new Musica(musicaRequest.Nome, musicaRequest.Duracao, album); var mensagens = musicaService.Validar(musica); if (mensagens.Count > 0) { return(BadRequest(mensagens)); } var musicaCadastrada = musicaRepository.AtualizarMusica(id, musica); contexto.SaveChanges(); return(Ok(musicaCadastrada)); }