public async Task <IActionResult> Devolver([FromBody] DevolucaoInput input) { var path = Startup.ContentRoot; var result = await _agendamentoService.Devolver(input, new GeraPdf(), path); if (!result.Success) { return(BadRequest(result.Message)); } return(StatusCode(201, result.Entity)); }
public async Task <EntityResponse> Devolver(DevolucaoInput resource, IGeraPdf pdfWriter, string pathPDF) { var agendamento = await _agendamentoRepository.FindByIdAsync(resource.AgendamentoId); if (agendamento == null) { return(new EntityResponse("Agendamento não encontrado")); } if (resource.OperadorId == 0) { return(new EntityResponse("Operador Obrigatório")); } var checklist = _mapper.Map <DevolucaoInput, Checklist>(resource); agendamento.DataHoraEntregaRealizada = DateTime.Now; double adicional = 0; if (!resource.CarroLimpo) { adicional += agendamento.SubTotal * 0.30; } if (!resource.TanqueCheio) { adicional += agendamento.SubTotal * 0.30; } if (resource.Amassados) { adicional += agendamento.SubTotal * 0.30; } if (resource.Arranhoes) { adicional += agendamento.SubTotal * 0.30; } agendamento.CustosAdicional = adicional; agendamento.ValorTotal = agendamento.SubTotal + adicional; agendamento.RealizadaVistoria = true; try { await _checklistRepository.AddAsync(checklist); await _unitOfWork.CompleteAsync(); agendamento.ChecklistId = checklist.Id; _agendamentoRepository.Update(agendamento); await _unitOfWork.CompleteAsync(); var veiculo = await _veiculoRepository.Filter(x => x.Id == agendamento.VeiculoId, v => v.Marca, v => v.Modelo, v => v.Categoria); new PdfService(pdfWriter).ContratoPagamentoPdf(agendamento, veiculo.First(), pathPDF); return(new EntityResponse(agendamento)); } catch (Exception e) { return(new EntityResponse($"Um erro ocorreu ao atualizar um agendamento: {e.Message}")); } }