public static async Task <CornTx[]> Deposit(BitcornContext dbContext, WalletDepositRequest request) { var receipts = new List <CornTx>(); try { var server = dbContext.WalletServer.FirstOrDefault((s) => s.Index == request.Index); int newDeposits = 0; var sql = new StringBuilder(); foreach (var payment in request.Payments) { decimal amount = payment.Amount; string address = payment.Address; string txid = payment.TxId; bool isLogged = await dbContext.IsDepositRegistered(txid); if (!isLogged) { newDeposits++; var wallet = await dbContext.WalletByAddress(address); if (wallet != null) { var cornTx = new CornTx(); cornTx.Amount = amount; cornTx.BlockchainTxId = txid; cornTx.ReceiverId = wallet.UserId; cornTx.SenderId = null; cornTx.Timestamp = DateTime.Now; cornTx.TxType = TransactionType.receive.ToString(); cornTx.Platform = "wallet-server"; cornTx.TxGroupId = Guid.NewGuid().ToString(); var deposit = new CornDeposit(); deposit.TxId = txid; deposit.UserId = wallet.UserId; sql.Append(TxUtils.ModifyNumber(nameof(UserWallet), nameof(UserWallet.Balance), amount, '+', nameof(UserWallet.UserId), wallet.UserId)); sql.Append(TxUtils.ModifyNumber(nameof(WalletServer), nameof(WalletServer.ServerBalance), amount, '+', nameof(WalletServer.Id), server.Id)); dbContext.CornTx.Add(cornTx); dbContext.CornDeposit.Add(deposit); receipts.Add(cornTx); } } } if (newDeposits > 0) { server.LastBalanceUpdateBlock = request.Block; int count = await dbContext.Database.ExecuteSqlRawAsync(sql.ToString()); await dbContext.SaveAsync(); } } catch (Exception e) { await BITCORNLogger.LogError(dbContext, e); } return(receipts.ToArray()); }