public HttpResponseMessage Guardar([FromBody] M_Pedidos c) { try { if (ValidarAutorizacion()) { var x = PedidosRepositorio.Guardar(c); if (x == false) { return(OkResponse("Hubo un error al recuperar el registro")); } else { return(OkResponse(x)); } } else { return(OkResponse("No tiene acceso")); } } catch (Exception) { return(ErrorResponse("Ha ocurrido un error")); throw; } }
public HttpResponseMessage ObtenerxID([FromUri] int id) { try { if (ValidarAutorizacion()) { var x = PedidosRepositorio.ObtenerxId(id); if (x == null) { return(OkResponse("Hubo un error al recuperar el registro")); } else { return(OkResponse(x)); } } else { return(OkResponse("No tiene acceso")); } } catch (Exception) { return(ErrorResponse("Ha ocurrido un error")); throw; } }
public HttpResponseMessage Actualizar([FromBody] M_Pedidos a) { try { if (ValidarAutorizacion()) { var x = PedidosRepositorio.Actualizar(a); if (x == false) { return(OkResponse("Hubo un error al tratar de actualizar")); } else { return(OkResponse(x)); } } else { return(OkResponse("No tiene acceso")); } } catch (Exception) { return(ErrorResponse("Ha ocurrido un error")); throw; } }
public async Task <IActionResult> RealizarPagamento([FromBody] PedidoModel pedidoModel) { using (var unitOfWork = _unitOfWorkFactory.CriarParaTenant(_contexto.CodigoTenant)) { var clientesRepositorio = new ClientesRepositorio(unitOfWork); var pedidosRepositorio = new PedidosRepositorio(unitOfWork); var cliente = await clientesRepositorio.ObterAsync(pedidoModel.CodigoCliente); var pedido = Pedido.Criar(cliente, pedidoModel.Dividas, pedidoModel.DadosPagamento); var pagamento = await _servicoPagamento.PagarAsync(pedido); if (!pagamento.Aprovado) { return(BadRequest(pagamento.NegadoPor)); } pedido.RealizarPagamento(pagamento); await _servicoEmail.EnviarObrigadoPeloPagamentoAsync(pedido); await _regrasPosPagamento.ExecutarRegrasPosPagamentoAsync(pedido); await pedidosRepositorio.IncluirAsync(pedido); await unitOfWork.CommitAsync(); return(Ok(pagamento)); } }
public async Task <IActionResult> RealizarPagamento([FromBody] PedidoModel pedidoModel) { using (var unitOfWork = _unitOfWorkFactory.CriarParaTenant(_contexto.CodigoTenant)) { var clientesRepositorio = new ClientesRepositorio(unitOfWork); var pedidosRepositorio = new PedidosRepositorio(unitOfWork); var cliente = await clientesRepositorio.ObterAsync(pedidoModel.CodigoCliente); var pedido = Pedido.Criar(cliente, pedidoModel.Dividas, pedidoModel.DadosPagamento); var pagamento = Pagamento.NovoPagamento(); try { pagamento = await _servicoPagamento.AutorizarPagamentoAsync(pedido); if (!pagamento.Aprovado) { return(BadRequest(pagamento.NegadoPor)); } pedido.RealizarPagamento(pagamento); try { await _servicoEmail.EnviarObrigadoPeloPagamentoAsync(pedido); } catch (Exception) { await _logger.Error("Email não foi enviado"); } try { await _regrasPosPagamento.ExecutarRegrasPosPagamentoAsync(pedido); } catch (Exception) { await _logger.Error("Executar regras manualmente"); } await pedidosRepositorio.IncluirAsync(pedido); await unitOfWork.CommitAsync(); } catch (Exception) { await unitOfWork.RollBackAsync(); return(BadRequest("Falha ao realizar pagamento")); } try { pagamento = await _servicoPagamento.CapturarPagamentoAsync(pedido); return(Ok(pagamento)); } catch (Exception) { await _logger.Error("Capturar manualmente o pagamento"); } return(Ok(pagamento)); } }
public async Task Handle(RealizarPagamentoParaPedidoPendenteComando message, IMessageHandlerContext context) { using (var unitOfWork = _unitOfWorkFactory.CriarParaTenant(message.CodigoTenant)) { var pedidosRepositorio = new PedidosRepositorio(unitOfWork); var pedidoResultado = await pedidosRepositorio.RecuperarAsync(message.PedidoId); if (await _servicoPagamento.CapturarPagamentoAsync(pedidoResultado.Sucesso) is var capturaResultado && capturaResultado.EhFalha) { await context.Send(new FalhaAoRealizarPagamentoComando(message.CodigoTenant, message.PedidoId, capturaResultado.Falha)); } await context.Send(new ConfirmarPagamentoDoPedidoComando(message.CodigoTenant, message.PedidoId, capturaResultado.Sucesso)); } }
public string Excluir(Pedidos entity) { AppContext contexto = new AppContext(); using (DbContextTransaction transacao = AppTransaction.CreateDbContextTransaction(contexto)) { _mensagem = new PedidosRepositorio(contexto).Excluir(entity); if (_mensagem == "") transacao.Commit(); else transacao.Rollback(); } return _mensagem; }
public async Task <IActionResult> RealizarPagamento([FromBody] PedidoModel pedidoModel) { using (var unitOfWork = _unitOfWorkFactory.CriarParaTenant(_contexto.CodigoTenant)) { var clientesRepositorio = new ClientesRepositorio(unitOfWork); var pedidosRepositorio = new PedidosRepositorio(unitOfWork); if (await clientesRepositorio.ObterAsync(pedidoModel.CodigoCliente) is var clienteResultado && clienteResultado.EhFalha) { return(BadRequest("Cliente inválido")); } var pedido = Pedido.NovoPendente(clienteResultado.Sucesso, pedidoModel.Dividas, pedidoModel.DadosPagamento); var pagamento = Pagamento.NovoPagamento(); if (await _servicoPagamento.AutorizarPagamentoAsync(pedido) is var autorizacaoResultado && autorizacaoResultado.EhFalha) { return(BadRequest("Aconteceu um problema ao realizar o pagamento")); } if (!pagamento.Aprovado) { return(BadRequest(pagamento.NegadoPor)); } pedido.RealizarPagamento(pagamento); if (await _servicoEmail.EnviarObrigadoPeloPagamentoAsync(pedido) is var emailEnviado && emailEnviado.EhFalha) { await _logger.Error("Admin favor enviar email de pagamento realizado"); } if (await _regrasPosPagamento.ExecutarRegrasPosPagamentoAsync(pedido) is var regrasExecutadas && regrasExecutadas.EhFalha) { await _logger.Error("Admin favor executar regras manualmente"); } await pedidosRepositorio.IncluirOuAtualizarAsync(pedido); if (await unitOfWork.CommitAsync() is var transacaoResultado && transacaoResultado.EhFalha) { return(BadRequest("Falha ao realizar pagamento")); } if (await _servicoPagamento.CapturarPagamentoAsync(pedido) is var capturaResultado && capturaResultado.EhFalha) { await _logger.Error("Capturar manualmente o pagamento"); } return(Ok(pagamento)); } }
public HttpResponseMessage ObtenerTodos() { try { if (ValidarAutorizacion()) { var x = PedidosRepositorio.ObtenerTodos(); return(OkResponse(x)); } else { return(OkResponse("No tiene acceso")); } } catch (Exception) { return(ErrorResponse("Ha ocurrido un error al Obtener Todos")); throw; } }
public async Task <IActionResult> RealizarPagamento([FromBody] PedidoModel pedidoModel) { using (var unitOfWork = _unitOfWorkFactory.CriarParaTenant(_contexto.CodigoTenant)) { var clientesRepositorio = new ClientesRepositorio(unitOfWork); var pedidosRepositorio = new PedidosRepositorio(unitOfWork); if (await clientesRepositorio.ObterAsync(pedidoModel.CodigoCliente) is var clienteResultado && clienteResultado.EhFalha) { return(BadRequest("Cliente inválido")); } var pedido = Pedido.NovoPendente(clienteResultado.Sucesso, pedidoModel.Dividas, pedidoModel.DadosPagamento); await pedidosRepositorio.IncluirOuAtualizarAsync(pedido); if (await unitOfWork.CommitAsync() is var transacaoResultado && transacaoResultado.EhFalha) { return(BadRequest("Falha ao realizar pagamento")); } await _bus.Enviar(new RealizarPagamentoParaPedidoPendenteComando(_contexto.CodigoTenant, pedido.Id)); return(Accepted(pedido)); } }
public async Task Handle(ConfirmarPagamentoDoPedidoComando message, IMessageHandlerContext context) { using (var unitOfWork = _unitOfWorkFactory.CriarParaTenant(message.CodigoTenant)) { var pedidosRepositorio = new PedidosRepositorio(unitOfWork); var pedidoResultado = await pedidosRepositorio.RecuperarAsync(message.PedidoId); pedidoResultado.Sucesso.RealizarPagamento(message.Pagamento); await pedidosRepositorio.IncluirOuAtualizarAsync(pedidoResultado.Sucesso); await unitOfWork.CommitAsync(); if (message.Pagamento.Aprovado) { await context.Publish(new PagamentoAprovadoEvento(message.CodigoTenant, message.PedidoId)); } else { await context.Publish(new PagamentoNegadoEvento(message.CodigoTenant, message.PedidoId)); } MarkAsComplete(); } }