Beispiel #1
0
 public Credit(CreditId id, AccountId accountId, PositiveMoney amount, DateTime transactionDate)
 {
     this.Id              = id;
     this.AccountId       = accountId;
     this.Amount          = amount;
     this.TransactionDate = transactionDate;
 }
Beispiel #2
0
 public Credit(CreditId creditId, AccountId accountId, DateTime transactionDate, decimal value, string currency)
 {
     this.CreditId        = creditId;
     this.AccountId       = accountId;
     this.TransactionDate = transactionDate;
     this.Amount          = new PositiveMoney(value, new Currency(currency));
 }
        public async Task <Credit> GetById(CreditId creditId)
        {
            var domainEvents = await _eventStore.GetEventsByStreamId(new CreditEventStreamId(creditId));

            if (domainEvents.Count == 0)
            {
                return(null);
            }

            return(new Credit(creditId, domainEvents.Cast <CreditDomainEvent>()));
        }
Beispiel #4
0
        public async Task AddCreditToLookup(CreditId creditId, OrganisationNumber organisationNumber)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                const string sql = "INSERT INTO CreditLookup (CreditId, OrganisationNumber, CreatedDate) VALUES (@creditId,@organisationNumber,@createdDate)";

                await connection.OpenAsync();

                using (var command = new SqlCommand(sql, connection))
                {
                    command.Parameters.AddWithValue("@creditId", (Guid)creditId);
                    command.Parameters.AddWithValue("@organisationNumber", organisationNumber.Number);
                    command.Parameters.AddWithValue("@createdDate", DateTimeOffset.Now);

                    await command.ExecuteNonQueryAsync();
                }
            }
        }
Beispiel #5
0
        public async Task <CreditViewModel> GetById(CreditId creditId)
        {
            var domainEvents = await _eventStore.GetEventsByStreamId(new CreditEventStreamId(creditId));

            if (domainEvents.Count == 0)
            {
                return(null);
            }

            var model = new CreditViewModel(creditId);

            foreach (var domainEvent in domainEvents.Cast <CreditDomainEvent>())
            {
                _projection.Apply(model, domainEvent);
            }

            return(model);
        }
        public async Task Handle(DomainEvent domainEvent)
        {
            var loanApplicationEvent = domainEvent as LoanApplicationDomainEvent;

            switch (loanApplicationEvent)
            {
            case ApplicationApproved applicationApproved:

                var application = await _queryMediator.MediateQuery(new GetLoanApplicationById(applicationApproved.ApplicationId));

                var creditId = CreditId.NewId();

                Log.Information("Processing {Event}, creating new credit with id {Id}", nameof(ApplicationApproved), creditId);

                await _commandMediator.MediateCommand(new RegisterCredit(creditId, applicationApproved.ApplicationId)
                {
                    OrganisationNumber = application.OrganisationNumber,
                    LoanAmount         = application.RequestedAmount
                });

                break;
            }
        }
Beispiel #7
0
 public RegisterCredit(CreditId id, LoanApplicationId?applicationId = null)
 {
     Id            = id;
     ApplicationId = applicationId;
 }
 public CreditViewModel(CreditId id)
 {
     Id = id;
 }
Beispiel #9
0
 public RegisterDisbursementPayout(CreditId id, Money amount)
 {
     Id     = id;
     Amount = amount;
 }
 public CreditEventStreamId(CreditId id)
 {
     _id = id.ToString();
 }
Beispiel #11
0
 public GetCreditById(CreditId creditId)
 {
     CreditId = creditId;
 }