public async Task <IActionResult> Put(int ChaveId, ChaveDto model) { try { var chave = await _repo.GetAllChaveAssyncById(ChaveId); if (chave == null) { return(NotFound()); } _mapper.Map(model, chave); _repo.Update(chave); if (await _repo.SaveChangesAssync()) { return(Created($"/api/chave/{chave.Id}", _mapper.Map <ChaveDto>(chave))); } } catch (System.Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } return(BadRequest()); }
public async Task <IActionResult> Post(ChaveDto model) { try { var chave = _mapper.Map <Chave>(model); _repo.Add(chave); if (await _repo.SaveChangesAssync()) { return(Created($"/api/chave/{chave.Id}", _mapper.Map <ChaveDto>(chave))); } } catch (System.Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } return(BadRequest()); }