public async Task <IActionResult> Put(Guid id, [FromBody] ImpedimentoTarefa obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != obj.Id) { return(BadRequest()); } try { _unitOfWork.ImpedimentoTarefaRepository.Update(obj); await _unitOfWork.SaveChangesAsync(); } catch (Exception) { if (!await ObjExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <ImpedimentoTarefa> > Post([FromBody] ImpedimentoTarefa obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { obj = await _unitOfWork.ImpedimentoTarefaRepository.AddAsync(obj); await _unitOfWork.SaveChangesAsync(); } catch (Exception) { if (await ObjExists(obj.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("GetImpedimentoTarefa", new { id = obj.Id }, obj)); }
public async Task UpdateImpedimentoTarefaCommand_Handle() { // Arrange IUnitOfWork unitOfWork = DbContextHelper.GetContext(); IMapper mapper = AutoMapperHelper.GetMappings(); Guid sistemaId = Guid.NewGuid(); await unitOfWork.SistemaRepository.AddAsync(MockEntityHelper.GetNewSistema(sistemaId)); Guid projetoId = Guid.NewGuid(); await unitOfWork.ProjetoRepository.AddAsync(MockEntityHelper.GetNewProjeto(sistemaId, projetoId)); Guid workflowId = Guid.NewGuid(); await unitOfWork.WorkflowRepository.AddAsync(MockEntityHelper.GetNewWorkflow(workflowId)); Guid recursoId = Guid.NewGuid(); await unitOfWork.RecursoRepository.AddAsync(MockEntityHelper.GetNewRecurso(recursoId)); Guid tipoTarefaId = Guid.NewGuid(); await unitOfWork.TipoTarefaRepository.AddAsync(MockEntityHelper.GetNewTipoTarefa(tipoTarefaId)); Guid tarefaId = Guid.NewGuid(); await unitOfWork.TarefaRepository.AddAsync(MockEntityHelper.GetNewTarefa(projetoId, workflowId, recursoId, tipoTarefaId, tarefaId)); Guid impedimentoId = Guid.NewGuid(); await unitOfWork.ImpedimentoRepository.AddAsync(MockEntityHelper.GetNewImpedimento(impedimentoId)); Guid impedimentoTarefaId = Guid.NewGuid(); DateTime dataInclusao = DateTime.Now; ImpedimentoTarefa impedimentoTarefa = MockEntityHelper.GetNewImpedimentoTarefa(tarefaId, impedimentoId, impedimentoTarefaId); await unitOfWork.ImpedimentoTarefaRepository.AddAsync(impedimentoTarefa); await unitOfWork.SaveChangesAsync(); unitOfWork.ImpedimentoTarefaRepository.Detatch(impedimentoTarefa); UpdateImpedimentoTarefaCommand request = new() { ImpedimentoTarefa = MockViewModelHelper.GetNewImpedimentoTarefa(tarefaId, impedimentoId, impedimentoTarefaId, dataInclusao) }; GetImpedimentoTarefaQuery request2 = new() { Id = impedimentoTarefaId }; // Act ImpedimentoTarefaHandler handler = new(unitOfWork, mapper); OperationResult response = await handler.Handle(request, CancellationToken.None); ImpedimentoTarefaViewModel response2 = await handler.Handle(request2, CancellationToken.None); // Assert Assert.True(response == OperationResult.Success); Assert.True(response2 != null); Assert.True(response2.Id == impedimentoTarefaId); Assert.True(response2.DataInclusao.Ticks == dataInclusao.Ticks); } }
public async Task <ActionResult <ImpedimentoTarefa> > Get(Guid id) { ImpedimentoTarefa impedimentoTarefa = await _unitOfWork.ImpedimentoTarefaRepository.GetAsync(id); if (impedimentoTarefa == null) { return(NotFound()); } return(Ok(impedimentoTarefa)); }
public async Task <IActionResult> Delete(Guid id) { ImpedimentoTarefa obj = await _unitOfWork.ImpedimentoTarefaRepository.GetAsync(id); if (obj == null) { return(NotFound()); } await _unitOfWork.ImpedimentoTarefaRepository.RemoveAsync(id); await _unitOfWork.SaveChangesAsync(); return(NoContent()); }
public async Task <OperationResult> Handle(RemoveImpedimentoTarefaCommand request, CancellationToken cancellationToken) { ImpedimentoTarefa obj = await _unitOfWork.ImpedimentoTarefaRepository.GetAsync(request.Id); if (obj == null) { return(OperationResult.NotFound); } await _unitOfWork.ImpedimentoTarefaRepository.RemoveAsync(request.Id); bool success = await _unitOfWork.SaveChangesAsync(); OperationResult result = success ? OperationResult.Success : OperationResult.Failed; return(result); }