Example #1
0
        public void Handle(InvoiceBalanceUpdated notification)
        {
            var invoice = _Mediator.Send(new GetInvoice {
                Id = notification.InvoiceId
            });

            notification.Apply(invoice);

            const string query = @"
                UPDATE Accounting.Invoice
                SET Balance = @Balance
                WHERE Id = @Id";

            _UnitOfWork.Execute(query, invoice);

            // This assumes a liability account, I'm considering invoices to
            // be liabilities for the company that receives an invoice
            var ledgerEntry = new GeneralLedgerEntry
            {
                CreditAmount = notification.Amount > 0 ? notification.Amount : 0,
                DebitAmount  = notification.Amount < 0 ? notification.Amount : 0,
                EntryDate    = notification.EventDate,
                Id           = _GuidGenerator.Generate(),
                LineItemId   = notification.LineItemId,
                CreatedOn    = notification.EventDate,
                CreatedById  = notification.UpdatedById
            };

            const string query2 = @"
                INSERT INTO Accounting.GeneralLedger (Id, CreditAmount, DebitAmount, LineItemId, CreatedOn, CreatedById)
                VALUES (@Id, @CreditAmount, @DebitAmount, @LineItemId, @CreatedOn, @CreatedById)";

            _UnitOfWork.Execute(query2, ledgerEntry);
        }
Example #2
0
        public EventHistoryItem Visit(InvoiceBalanceUpdated evt)
        {
            evt.Apply(_Invoice);

            var historyItem = CreateEventHistoryItem(evt);

            historyItem.Message = $"New balance of ${_Invoice.Balance}";

            return(historyItem);
        }