Esempio n. 1
0
        public TakePaymentCommand ToCommand(Guid loanId)
        {
            var command = new TakePaymentCommand(Guid.NewGuid(), loanId,
                                                 this.Amount,
                                                 DateTimeOffset.Now);

            return(command);
        }
Esempio n. 2
0
        public void TakePayment(TakePaymentCommand command)
        {
            if (command.TransactionDateTime < _createdOn)
            {
                throw new ArgumentException("Transaction date can not be prior to loan creation", nameof(command));
            }
            if (command.Amount <= decimal.Zero)
            {
                throw new ArgumentException("Transaction amount must be positive", nameof(command));
            }

            AddEvent(new PaymentTakenEvent(Guid.NewGuid().ToString(), command.TransactionDateTime, command.Amount));
            if (_balance >= decimal.Zero)
            {
                AddEvent(new LoanSettledEvent(command.TransactionDateTime));
            }
            if (_balance > decimal.Zero)
            {
                AddEvent(new LoanOverPaidEvent(command.TransactionDateTime, _balance));
            }
        }