public async Task <IActionResult> Create([FromBody] TarefaResource tarefaResource) { if (tarefaResource == null) { return(NotFound()); } try { var tarefa = new Tarefa(); if (ModelState.IsValid) { tarefa = TarefaMapper.ResourceToModel(tarefaResource, tarefa); } _unitOfWork.Tarefas.Add(tarefa); await _unitOfWork.CompleteAsync(); TarefaMapper.ModelToResource(tarefa); return(Ok(tarefa)); } catch (Exception exception) { LogError.LogErrorWithSentry(exception); return(BadRequest()); } }
public async Task <IActionResult> Edit(int id, [FromBody] TarefaResource tarefaResource) { try { var tarefa = await _unitOfWork.Tarefas.GetByIdAsync(id); if (ModelState.IsValid) { tarefa = TarefaMapper.ResourceToModel(tarefaResource, tarefa); await _unitOfWork.CompleteAsync(); TarefaMapper.ModelToResource(tarefa); } return(Ok(tarefa)); } catch (Exception e) { LogError.LogErrorWithSentry(e); return(BadRequest(ModelState)); } }