예제 #1
0
        public async Task Handle(Deposit2Command command)
        {
            Access.CheckRole("Admin");

            var aggregate = new Transaction2Aggregate(command.AccountID);
            await aggregate.Deposit(command.Amount, command.Description);
        }
예제 #2
0
        public async Task <bool> HasBalance(Guid accountID)
        {
            Access.CheckRole("Admin");

            var aggregate = new Transaction2Aggregate(accountID);
            await aggregate.RebuildOneEvent();

            return(aggregate.LastEventNumber.HasValue);
        }
예제 #3
0
        public async Task Handle(Transfer2Command command)
        {
            Access.CheckRole("Admin");

            var aggregateTo   = new Transaction2Aggregate(command.ToAccountID);
            var aggregateFrom = new Transaction2Aggregate(command.FromAccountID);

            await aggregateFrom.TransferFrom(command.ToAccountID, command.Amount, command.Description);

            await aggregateTo.TransferTo(command.FromAccountID, command.Amount, command.Description);
        }
예제 #4
0
        public async Task <Balance2Model> GetBalance(Guid accountID)
        {
            Access.CheckRole("Admin");

            var aggregate = new Transaction2Aggregate(accountID);
            await aggregate.Rebuild();

            var model = new Balance2Model()
            {
                AccountID             = aggregate.ID,
                Balance               = aggregate.Balance,
                LastTransactionAmount = aggregate.LastTransactionAmount,
                LastTransactionDate   = aggregate.LastEventDate
            };

            return(model);
        }
예제 #5
0
        public async Task <ICollection <Transaction2Model> > GetTransactions(Guid accountID)
        {
            Access.CheckRole("Admin");

            var aggregate = new Transaction2Aggregate(accountID);
            var models    = new List <Transaction2Model>();

            while (await aggregate.RebuildOneEvent())
            {
                var model = new Transaction2Model()
                {
                    AccountID   = aggregate.ID,
                    Balance     = aggregate.Balance,
                    Amount      = aggregate.LastTransactionAmount.Value,
                    Date        = aggregate.LastEventDate.Value,
                    Description = aggregate.LastTransactionDescription,
                    Event       = aggregate.LastEventName
                };
                models.Add(model);
            }
            return(models);
        }