protected override async Task CustomSeedAsync() { #region Inicia base com lançamentos var lancamentos = new List <Lancamento>() { new Lancamento(Guid.NewGuid(), DateTime.UtcNow, 123, 980, 222), new Lancamento(Guid.NewGuid(), DateTime.UtcNow, 980, 321, 333), new Lancamento(Guid.NewGuid(), DateTime.UtcNow, 123, 321, 444) }; await Task.WhenAll(lancamentos.Select(x => _lancamentoRepository.AddAsync(new Lancamento(x.Id, x.Data, x.ContaOrigem, x.ContaDestino, x.Valor)))); #endregion #region Inicia base com contas var accs = new List <ContaCorrente>() { new ContaCorrente(Guid.NewGuid(), 123), new ContaCorrente(Guid.NewGuid(), 980), new ContaCorrente(Guid.NewGuid(), 321) }; await Task.WhenAll(accs.Select(a => _accRepo.AddAsync(new ContaCorrente(a.Id, a.Numero)))); #endregion }
public async Task HandleAsync(LancamentoCreated @event) { await _lancRepo.AddAsync(new Lancamento { Id = @event.Id, Data = @event.Data, ContaOrigem = @event.ContaOrigem, ContaDestino = @event.ContaDestino }); Console.WriteLine($"Lancamento criado: @{@event.Id}"); }
public async Task AddAsync(Guid id, DateTime data, int contaOrigem, int contaDestino, decimal valor) { var accOrigem = await _accRepo.GetAsync(contaOrigem); var accDestino = await _accRepo.GetAsync(contaDestino); if (accOrigem == null) { throw new TransferException("Conta origem não existe", $"Conta Origem: '{contaOrigem} não encontrada"); } if (accDestino == null) { throw new TransferException("Conta destino não existe", $"Conta Destino: '{accDestino} não encontrada"); } var lancamento = new Lancamento(id, data, contaOrigem, contaDestino, valor); await _lancacamentoRepo.AddAsync(lancamento); }