public async Task <Balance> CreateAndUpdateBalance(Investment investment) { try { var movement = new Movement(investment.Value, investment.Description, EMovementCategory.Investment, EMovementType.Investment, investment.AccountId, investment.UserId); var userBalance = await _transactionService.CreateOrUpdateBalance(movement); investment.SetMovement(movement.Id); await CreateInvestment(investment); var userInvestmentBalance = await _investmentBalanceRepository.Get(investment.UserId, investment.AccountId); if (userInvestmentBalance is null) { return(await FirstInvestmentBalance(investment.UserId, investment.AccountId, investment.Value)); } userInvestmentBalance.UpdateBalance(investment.Value); await UpdateInvestmentBalance(userInvestmentBalance); return(userBalance); } catch (Exception e) { throw e; } }