コード例 #1
0
        public void Rechrage(decimal amount, Guid requestId)
        {
            CheckRule(new UserBalanceNonnegativeRule(amount));

            var transcation = UserTranscation.Create(null, this, requestId, amount);

            _Transfer(transcation);
        }
コード例 #2
0
        public void TransferTo(User recevier, decimal amount, Guid requestId)
        {
            CheckRule(new UserBalanceNonnegativeRule(amount));

            var transcation = UserTranscation.Create(this, recevier, requestId, amount);

            recevier._Transfer(transcation);
            this._Transfer(UserTranscation.CreateReverse(transcation));

            AddDomainEvent(new UserTransferSuccessEvent(this, recevier, amount));
        }
コード例 #3
0
 private void _Transfer(UserTranscation trancation)
 {
     if (trancation.Dircition == TransferDircition.Reduce)
     {
         CheckRule(new UserIsufficientBalanceRule(Balance, trancation.Amount));
         Balance -= trancation.Amount;
     }
     else
     {
         Balance += trancation.Amount;
     }
     _transcations ??= new List <UserTranscation>();
     _transcations.Add(trancation);
 }