Exemplo n.º 1
0
        public async Task Add(OpenedDomainEvent domainEvent)
        {
            using (IDbConnection db = new SqlConnection(connectionString))
            {
                string insertAccountSQL = "INSERT INTO Account (Id, CustomerId, Version) VALUES (@Id, @CustomerId, @Version)";

                DynamicParameters accountParameters = new DynamicParameters();
                accountParameters.Add("@id", domainEvent.AggregateRootId);
                accountParameters.Add("@customerId", domainEvent.CustomerId);
                accountParameters.Add("@version", domainEvent.Version);

                int accountRows = await db.ExecuteAsync(insertAccountSQL, accountParameters);

                string insertCreditSQL = "INSERT INTO [Transaction] (Id, Amount, TransactionDate, AccountId, TransactionType) " +
                                         "VALUES (@Id, @Amount, @TransactionDate, @AccountId, @TransactionType)";

                DynamicParameters transactionParameters = new DynamicParameters();
                transactionParameters.Add("@id", domainEvent.TransactionId);
                transactionParameters.Add("@amount", domainEvent.TransactionAmount.Value);
                transactionParameters.Add("@transactionDate", domainEvent.TransactionDate);
                transactionParameters.Add("@accountId", domainEvent.AggregateRootId);
                transactionParameters.Add("@transactionType", 1);

                int debitRows = await db.ExecuteAsync(insertCreditSQL, transactionParameters);
            }
        }
Exemplo n.º 2
0
        public async Task Add(OpenedDomainEvent domainEvent)
        {
            Account account = new Account();

            account.Apply(domainEvent);

            await mongoContext.Accounts.InsertOneAsync(account);
        }
Exemplo n.º 3
0
        public async Task Add(OpenedDomainEvent domainEvent)
        {
            Account account = new Account();

            account.Apply(domainEvent);
            await context.Accounts.AddAsync(account);

            int affectedRows = await context.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public void Open(Guid customerId, Credit credit)
        {
            var domainEvent = new OpenedDomainEvent(
                Id,
                customerId,
                Version,
                credit.Id,
                credit.Amount,
                credit.TransactionDate
                );

            Raise(domainEvent);
        }
Exemplo n.º 5
0
        protected void When(OpenedDomainEvent domainEvent)
        {
            //
            // Open an Account
            //

            Id           = domainEvent.AggregateRootId;
            CustomerId   = domainEvent.CustomerId;
            Transactions = new TransactionCollection();

            Transaction credit = new Credit(
                domainEvent.AggregateRootId,
                domainEvent.TransactionId,
                domainEvent.TransactionAmount,
                domainEvent.TransactionDate);

            Transactions.Add(credit);
        }