public async Task <ActionResult <TrocaResource> > Update(int id, [FromBody] UpdateTrocaResource updateTrocaResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var trocaToUpdate = await _trocaService.GetById(id); if (trocaToUpdate == null) { return(NotFound("Troca não encontrado")); } var troca = _mapper.Map <Troca>(updateTrocaResource); if (await _trocaService.SaldoInsuficiente(trocaToUpdate, troca)) { return(BadRequest("Saldo insuficiente")); } var newTroca = await _trocaService.Update(trocaToUpdate, troca); var newTrocaResource = _mapper.Map <TrocaResource>(newTroca); return(Ok(newTrocaResource)); }
public void Update(TrocaViewModel trocaViewModel) { _trocaService.Update(Mapper.Map <TrocaViewModel, Troca>(trocaViewModel)); }