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> GetAll() { var tarefas = await _unitOfWork.Tarefas.GetAllAsync(); List <TarefaResource> tarefaResource = new List <TarefaResource>(); if (tarefas == null) { return(NoContent()); } foreach (var tarefa in tarefas) { tarefaResource.Add(TarefaMapper.ModelToResource(tarefa)); } return(Ok(tarefaResource)); }
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)); } }
public async Task <IActionResult> Get(int id) { var tarefa = await _unitOfWork.Tarefas.GetByIdAsync(id); return(Ok(TarefaMapper.ModelToResource(tarefa))); }