public async Task <Cacion> ActualizarCancionAsync(int artistaId, int id, Cacion cancion) { //await validarArtistaId(artistaId); //if (cancion.Id != null && cancion.Id != id) //{ // throw new InvalidOperationException("song URL id and song body id should be the same"); //} var artista = await validarArtistaId(artistaId); if (id != cancion.Id && cancion.Id != null) { throw new Exception("Id of the cancion in URL needs to be the same that the object"); } if (artistaId != artista.Id) { throw new Exception("The id of Artist isn't correct"); } cancion.Id = id; var cacionEntity = mapper.Map <CacionEntity>(cancion); windAppRepository.UpdateCancion(cacionEntity); if (await windAppRepository.SaveChangesAsync()) { return(mapper.Map <Cacion>(cacionEntity)); } throw new Exception("There were an error with the DB"); }
public async Task <Artista> ActualizarArtistaAsync(int id, Artista newArtista) { if (id != newArtista.Id) { throw new InvalidOperationException("URL id needs to be the same as Author id"); } await ValidateArtista(id); newArtista.Id = id; var artistaEntity = mapper.Map <ArtistaEntity>(newArtista); artistaRapository.UpdateArtistaAsync(artistaEntity); if (await artistaRapository.SaveChangesAsync()) { return(mapper.Map <Artista>(artistaEntity)); } throw new Exception("There were an error with the DB"); }