public async Task <WalletTableModel> GetUpdatedWalletAsync(string userId) { WalletTableModel wallet = await _walletsRepository.GetUserWalletAsync(userId, "ZEC"); if (wallet == null) { return(null); } List <IncomeWalletTableModel> incomeZecWallets = await _walletsRepository.GetUserIncomeWalletsByAcronimAsync(userId, "ZEC"); List <IncomeTransactionTableModel> transactionModels = await _transactionsRepository.GetIncomeTransactions(userId, "ZEC"); List <string> savedTransactions = transactionModels.Select(x => x.TransactionId).ToList(); foreach (var incomeZecWallet in incomeZecWallets) { List <ZecDeltas> addressIncomeTransactions = GetAddressIncomingTransactions(incomeZecWallet.Address); foreach (var tx in addressIncomeTransactions) { if (!savedTransactions.Contains(tx.TxId)) { var transaction = await _transactionsRepository.CreateIncomeTransactionAsync(new IncomeTransactionTableModel() { CurrencyAcronim = "ZEC", TransactionId = tx.TxId, Amount = tx.Satoshis / 100000000, UserId = userId, FromAddress = null, ToAddress = tx.Address, TransactionFee = 0, }); var result = await _balanceProvider.Income(wallet, transaction); await _eventsRepository.CreateEventAsync(new EventTableModel() { UserId = userId, Type = (int)EventTypeEnum.Income, Comment = $"Income transaction {transaction.CurrencyAcronim}", WhenDate = DateTime.Now, CurrencyAcronim = transaction.CurrencyAcronim, StartBalance = result.StartBalanceReceiver, ResultBalance = result.ResultBalanceReceiver, PlatformCommission = result.Commission, Value = transaction.Amount }); transaction.PlatformCommission = result.Commission; wallet.Value = result.ResultBalanceReceiver.Value; transaction.PlatformCommission = result.Commission; await _transactionsRepository.CreateIncomeTransactionAsync(transaction); } } } await _walletsRepository.UpdateWalletBalanceAsync(wallet); return(wallet); }