public async Task <bool> Handle(AlterarTipoPagamentoCommand message, CancellationToken cancellationToken) { bool success = false; if (!message.EhValido()) { await NotificarErrosValidacao(message); return(success); } var tipoPagamentoDatabase = _tipoPagamentoRepository.GetById(message.Data.Id); if (tipoPagamentoDatabase == null) { await _mediatorHandler.PublicarNotificacao(new DomainNotification(message.MessageType, $"O tipo de pagamento com o Id {message.Data.Id} não foi localizado!")); return(success); } try { tipoPagamentoDatabase.AlteraDescricao(message.Data.Descricao); tipoPagamentoDatabase.AlteraRequerDadosCartao(message.Data.RequerDadosCartao); tipoPagamentoDatabase.AlteraEhCartaoCorporativo(message.Data.EhCartaoCorporativo); tipoPagamentoDatabase.AlteraRequerDadosConta(message.Data.RequerDadosConta); _tipoPagamentoRepository.Update(tipoPagamentoDatabase); success = await Commit(); } catch (Exception ex) { Debug.WriteLine(ex.Message); await _mediatorHandler.PublicarNotificacao(new DomainNotification(message.MessageType, $"Ocorreu um erro inesperado ao Alterar Tipo Pagamento")); return(success); } if (success) { await _mediatorHandler.PublicarEvento(new Events.TipoPagamento.TipoPagamentoAlteradoEvent(message.Data)); } return(success); }
public async Task <bool> Handle(AdicionarColaboradorCommand message, CancellationToken cancellationToken) { var success = await Validar(message) && await AdicionarColaboradorCommandEhConsistente(message); if (!success) { return(success); } try { if (message.FuncaoId.HasValue) { var funcao = _funcaoRepository.GetById(message.FuncaoId.Value); message.Data.AtribuirFuncao(funcao); } foreach (var id in message.TipoPagamentoIds) { var tipoPagamento = _tipoPagamentoRepository.GetById(id); var tipoPagamentoColaborador = new TiposPagamentoColaborador(tipoPagamento, message.Data); message.Data.AtribuirTipoPagamento(tipoPagamentoColaborador); } _colaboradorRepository.Add(message.Data); await _colaboradorRepository.UnitOfWork.Commit(); success = true; } catch (Exception ex) { success = false; Debug.WriteLine(ex.Message); await _mediatorHandler.PublicarNotificacao(new DomainNotification(message.MessageType, $"Ocorreu um erro inesperado ao Adicionar Colaborador")); return(success); } if (success) { await _mediatorHandler.PublicarEvento(new Events.Colaborador.ColaboradorAdicionadoEvent(message.Data)); } return(success); }
public TipoPagamentoViewModel ObterPorId(Guid id) { return(_mapper.Map <TipoPagamentoViewModel>(_tipoPagamentoRepository.GetById(id))); }