public async Task ResetBalanceAsync(DepositWalletKey key, long transactionBlock) { using (var context = new WalletManagerContext(_dbContextOptionsBuilder.Options)) { var existing = await context.EnrolledBalances.FindAsync(key.BlockchainId, key.BlockchainAssetId, key.WalletAddress.ToLower(CultureInfo.InvariantCulture)); if (existing != null) { context.EnrolledBalances.Update(existing); } else { var newEntity = new EnrolledBalanceEntity() { BlockchianId = key.BlockchainId, BlockchainAssetId = key.BlockchainAssetId, WalletAddress = key.WalletAddress.ToLower(CultureInfo.InvariantCulture), Balance = "0", BlockNumber = transactionBlock, OriginalWalletAddress = key.WalletAddress }; context.EnrolledBalances.Add(newEntity); } await context.SaveChangesAsync(); } }
private static EnrolledBalance MapFromEntity(EnrolledBalanceEntity entity) { if (entity == null) { return(null); } BigInteger.TryParse(entity.Balance, out var balance); return(EnrolledBalance.Create( new DepositWalletKey(entity.BlockchainAssetId, entity.BlockchianId, entity.OriginalWalletAddress), balance, entity.BlockNumber)); }