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 <ActionResult <Cacion> > PostCancion(int artistaId, [FromBody] Cacion cancion) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var newSonge = await cancionService.AñadirCancionAsync(artistaId, cancion); return(Created($"/api/artista/{artistaId}/canciones/{cancion.Id}", newSonge)); } catch (InvalidOperationException ex) { return(BadRequest(ex.Message)); } catch (NotFoundException ex) { return(NotFound(ex.Message)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public async Task <bool> ActualizarVotoAsync(int artistaId, int id, Cacion cancion) { var artista = await validarArtistaId(artistaId); if (artistaId != artista.Id) { throw new Exception("The id of Artist isn't correct"); } cancion.Id = id; var cancionEntity = mapper.Map <CacionEntity>(cancion); windAppRepository.UpdateVotos(cancionEntity, 1); if (await windAppRepository.SaveChangesAsync()) { return(true); } throw new Exception("There were an error with the DB"); }
public async Task <Cacion> AñadirCancionAsync(int artistaId, Cacion cancion) { if (cancion.ArtistaId != null && artistaId != cancion.ArtistaId) { throw new InvalidOperationException("URL artisttt id and artistId should be equal"); } cancion.ArtistaId = artistaId; var artistaEntity = await validarArtistaId(artistaId); var cancionEntity = mapper.Map <CacionEntity>(cancion); cancionEntity.Artista = artistaEntity; //mapper.Map(cancion, cacnionEntity); windAppRepository.CreateCancion(cancionEntity); if (await windAppRepository.SaveChangesAsync()) { return(mapper.Map <Cacion>(cancionEntity)); } throw new Exception("There were an error with the DB"); }
public async Task <ActionResult <bool> > PutCancionVoto(int artistaId, int cancionId, [FromBody] Cacion cancion) { try { return(Ok(await cancionService.ActualizarVotoAsync(artistaId, cancionId, cancion))); } catch { throw new Exception("Not possible to show"); } }