public async Task <ActionResult> Put(int comitenteId, ComitenteDTO model) { try { var comitente = await _repo.GetComitenteByIdAsync(comitenteId); if (comitente == null) { return(NotFound()); } _mapper.Map(model, comitente); _repo.Update(comitente); if (await _repo.SaveChangesAsync()) { return(Created($"api/comitente/{comitente.Id}", _mapper.Map <ComitenteDTO>(comitente))); } } catch (System.Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou")); } return(BadRequest()); }
public async Task <ActionResult> Post(ComitenteDTO model) { try { var comitente = _mapper.Map <Comitente>(model); _repo.Add(comitente); if (await _repo.SaveChangesAsync()) { return(Created($"api/comitente/{comitente.Id}", _mapper.Map <ComitenteDTO>(comitente))); } } catch (System.Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou")); } return(BadRequest()); }