コード例 #1
0
        public bool Withdraw(AccountTransactionModel accountModel)
        {
            var account       = _checkingAccountRepository.GetById(accountModel.AccountOriginId) ?? throw new NotFoundException();
            var withdrawValue = accountModel.Value;

            if (withdrawValue < 0)
            {
                throw new InvalidObjectException();
            }

            account.Withdraw(withdrawValue);

            return(_checkingAccountRepository.Update(account));
        }
コード例 #2
0
        public bool Transfer(AccountTransactionModel accountModel)
        {
            var transfeValue = accountModel.Value;

            if (accountModel.AccountOriginId == accountModel.AccountDestinationId || transfeValue < 0)
            {
                throw new InvalidObjectException();
            }

            var accountOriginDb      = _checkingAccountRepository.GetById(accountModel.AccountOriginId) ?? throw new NotFoundException();
            var accountDestinationDb = _checkingAccountRepository.GetById(accountModel.AccountDestinationId) ?? throw new NotFoundException();

            accountOriginDb.Transfer(transfeValue, accountDestinationDb);

            _checkingAccountRepository.Update(accountDestinationDb);
            return(_checkingAccountRepository.Update(accountOriginDb));
        }