Esempio n. 1
0
        /// Updates Loan
        /// Assume deduplication of messages is handled somewhere else
        /// ASK PM: What do we do with Payments received for loans that don't exists or are inactive / fully paid?
        public async Task <Loan> UpdateLoanAsync(PaymentReceived paymentReceived)
        {
            if (ActiveLoanExists(paymentReceived.CustomerId))
            {
                var loan = GetLoan(paymentReceived.CustomerId);

                loan.UpdateTotalLoanPayed(paymentReceived.PaymentAmount);
                _loans[loan.CustomerId] = loan;

                if (loan.State() == LoanState.FINISHED)
                {
                    var loanFinished = new LoanFinished(loan.CustomerId, paymentReceived.CorrelationId);
                    await _eventSender.SendLoanFinishedAsync(loanFinished);
                }
                else
                {
                    var loanUpdated = new LoanUpdated(paymentReceived.CustomerId, loan.DailyUsageAllowance(), paymentReceived.CorrelationId);
                    await _eventSender.SendLoanUpdatedAsync(loanUpdated);
                }

                return(loan);
            }

            return(null);
        }
Esempio n. 2
0
 public Task SendLoanFinishedAsync(LoanFinished loanFinished)
 {
     throw new NotImplementedException();
 }