コード例 #1
0
        public async Task <bool> Add(WalletAggregate wallet, SecureString password)
        {
            if (wallet == null)
            {
                throw new ArgumentNullException(nameof(wallet));
            }

            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            var exists = await _currentDbContext.Wallets.AnyAsync(w => w.Name == wallet.Name).ConfigureAwait(false);

            if (exists)
            {
                throw new DataWalletException(ErrorCodes.AlreadyExists);
            }

            var walletJson = ToJson(wallet);
            var record     = new Wallet(wallet.Name, Protect(walletJson, password));

            _currentDbContext.Wallets.Add(record);
            await _currentDbContext.SaveChangesAsync().ConfigureAwait(false);

            return(true);
        }
コード例 #2
0
        public async Task <bool> Add(string scAddr, string filterId)
        {
            if (string.IsNullOrWhiteSpace(scAddr))
            {
                throw new ArgumentNullException(nameof(scAddr));
            }

            if (string.IsNullOrWhiteSpace(filterId))
            {
                throw new ArgumentNullException(nameof(filterId));
            }

            var exists = await _currentDbContext.SolidityContracts.AnyAsync(w => w.Address == scAddr).ConfigureAwait(false);

            if (!exists)
            {
                return(false);
            }

            _currentDbContext.SolidityFilters.Add(new SolidityFilter
            {
                Id = filterId,
                SmartContractAddress = scAddr
            });
            await _currentDbContext.SaveChangesAsync().ConfigureAwait(false);

            return(true);
        }
コード例 #3
0
        public async Task <bool> Insert(SolidityContractAggregate contract)
        {
            if (contract == null)
            {
                throw new ArgumentNullException(nameof(contract));
            }

            var exists = await _currentDbContext.SolidityContracts.AnyAsync(w => w.Address == contract.Address).ConfigureAwait(false);

            if (exists)
            {
                return(false);
            }

            var record = new SolidityContract
            {
                Address = contract.Address,
                Code    = contract.Code,
                Abi     = contract.Abi
            };

            _currentDbContext.SolidityContracts.Add(record);
            await _currentDbContext.SaveChangesAsync().ConfigureAwait(false);

            return(true);
        }
コード例 #4
0
 /// <summary>
 /// 自带事务,调用此方法保存
 /// </summary>
 public async Task <int> SaveChangesAsync()
 {
     try
     {
         return(await CurrentDbContext.SaveChangesAsync());
     }
     catch (DbException ex)
     {
         throw new CustomSystemException($"数据库保存失败!{ex.Message}", ResponseCode.DbEx);
     }
     catch (Exception ex)
     {
         throw new CustomSystemException($"数据库保存失败!{ex.Message}", ResponseCode.DbEx);
     }
 }
コード例 #5
0
 public void Dispose()
 {
     _db.SaveChangesAsync();
     _db.Dispose();
 }
コード例 #6
0
ファイル: UnitOfWork.cs プロジェクト: iooc/cfms
 ///// <summary>
 ///// 初始化工作单元服务的新实例
 ///// </summary>
 ///// <param name="_dbContext">注入每次请求周期的数据访问上下文</param>
 //public UnitOfWork(DbContext _dbContext)
 //{
 //    CurrentDbContext = _dbContext;
 //}
 /// <summary>
 /// 确认工作单元提交
 /// </summary>
 /// <returns></returns>
 public override Task SaveChanges()
 {
     return(CurrentDbContext.SaveChangesAsync());
 }