public async Task <IActionResult> Post(User user) { try { _repo.Add(user); if (await _repo.SaveChangesAsync()) { return(Created($"/api/user/{user.Id}", user)); } } catch (System.Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Falha no banco de dados")); } return(BadRequest()); }
public async Task <IActionResult> Post(TodoDTO todoDTO) { try { var todo = _mapper.Map <Todo>(todoDTO); _repo.Add(todo); if (await _repo.SaveChangesAsync()) { return(Created($"/api/todo/{todo.Id}", _mapper.Map <TodoDTO>(todo))); } } catch (System.Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Bd error {ex.Message}")); } return(BadRequest()); }