コード例 #1
0
        private async Task HandleSubscriptionAsync(ISubscriptionPayment payment, IBalanceHolder senderBalanceHolder)
        {
            var senderBalance = senderBalanceHolder.Balance;

            using var transaction        = _unitOfWork.BeginTransaction();
            senderBalance.PersonalFunds -= payment.Amount;
            transaction.Update(senderBalance);

            await transaction.InsertAsync(new BalanceTransaction(TransactionType.Withdrawal, senderBalance.Id,
                                                                 payment.Amount, payment.Description));
        }
コード例 #2
0
        private async Task HandleTransferAsync(ITransferPayment payment, IBalanceHolder senderBalanceHolder, IBalanceHolder recipientBalanceHolder)
        {
            var senderBalance    = senderBalanceHolder.Balance;
            var recipientBalance = recipientBalanceHolder.Balance;

            using var transaction           = _unitOfWork.BeginTransaction();
            senderBalance.PersonalFunds    -= payment.Amount;
            recipientBalance.PersonalFunds += payment.Amount;

            transaction.Update(senderBalance);
            transaction.Update(recipientBalance);

            await transaction.InsertAsync(new BalanceTransaction(TransactionType.Withdrawal, senderBalance.Id,
                                                                 payment.Amount, payment.Description));

            await transaction.InsertAsync(new BalanceTransaction(TransactionType.Refill, recipientBalance.Id,
                                                                 payment.Amount, payment.Description));
        }