public void AddAccountTransaction(AccountTransaction accountTransaction, bool saveIfZeroAmount = false) { if (accountTransaction.Amount != 0 || saveIfZeroAmount) { _transactionRepository.Add(accountTransaction); UpdatePaidUntilIfRental(accountTransaction); } }
public async Task <bool> Handle(BuyInvestmentToolCommand request, CancellationToken cancellationToken) { //Start source account process var sourceAccount = await _accountRepository.FindOrDefaultAsync(Guid.Parse(request.SourceAccountId)); if (sourceAccount == null || !sourceAccount.CheckBalanceForWithdraw(request.Amount * request.Rate ?? 1)) { return(false); } var accountBalanceChangedIntegrationEvent = new AccountBalanceChangedIntegrationEvent(); accountBalanceChangedIntegrationEvent.EffectedAccountIds.Add(Guid.Parse(request.SourceAccountId)); var transactionForSourceAccount = new AccountTransaction(Guid.Parse(request.SourceAccountId), TransactionType.PullInvestmentToolFromAccount.EnumId, request.TransactionDate, request.Amount * request.Rate ?? 1, request.Rate ?? 1); _logger.LogInformation("----- Creating Transaction - Transaction: {@Transaction}", transactionForSourceAccount); _accountTransactionRepository.Add(transactionForSourceAccount); //Start destination account process var destinationAccount = await _accountRepository.FindOrDefaultAsync(Guid.Parse(request.DestinationAccountId)); if (destinationAccount == null) { return(false); } accountBalanceChangedIntegrationEvent.EffectedAccountIds.Add(Guid.Parse(request.DestinationAccountId)); await _imsIntegrationEventService.AddAndSaveEventAsync(accountBalanceChangedIntegrationEvent); var transactionForDestinationAccount = new AccountTransaction(Guid.Parse(request.DestinationAccountId), TransactionType.BuyInvestmentTool.EnumId, request.TransactionDate, request.Amount, request.Rate ?? 1); _logger.LogInformation("----- Creating Transaction - Transaction: {@Transaction}", transactionForDestinationAccount); _accountTransactionRepository.Add(transactionForDestinationAccount); return(await _accountTransactionRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)); }
public async Task <bool> Handle(InvestInvestmentToolToAccountCommand request, CancellationToken cancellationToken) { //Notify for reporting var accountBalanceChangedIntegrationEvent = new AccountBalanceChangedIntegrationEvent(); accountBalanceChangedIntegrationEvent.EffectedAccountIds.Add(Guid.Parse(request.AccountId)); await _imsIntegrationEventService.AddAndSaveEventAsync(accountBalanceChangedIntegrationEvent); var transaction = new AccountTransaction(Guid.Parse(request.AccountId), request.TransactionTypeId, request.TransactionDate, request.Amount, request.Rate ?? 1); _logger.LogInformation("----- Creating Transaction - Transaction: {@Transaction}", transaction); _accountTransactionRepository.Add(transaction); return(await _accountTransactionRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken)); }
public async Task <bool> Handle(Command request, CancellationToken cancellationToken) { var account = await _accountRepository.GetByCPF(request.CPF); if (account is null) { throw new Exception($"Não existe a conta virtual com CPF '{request.CPF}'."); } var result = account.Debit(request.Value); if (result) { var transaction = new AccountTransaction(account.Id, request.Description, TransactionType.Debit, request.Value); _ = await _accountTransactionRepository.Add(transaction); _ = _accountRepository.Update(account); } return(result); }
private Guid AddAccountTransaction(CreateAccountTransactionBalanceRequest request, Guid principal) { return(_accountTransactionRepository.Add(request, principal).Value.Id); }