private void Apply(AccountCheckDepositedEvent depositedEvent)
        {
            var depositDate = depositedEvent.CreditDate.AddDays(1);

            while (!(depositDate.DayOfWeek >= DayOfWeek.Monday && depositDate.DayOfWeek <= DayOfWeek.Friday))
            {
                depositDate = depositDate.AddDays(1);
            }
            if (DateTime.UtcNow.Date >= depositDate.Date)
            {
                Balance += depositedEvent.Amount;
            }
        }
Exemple #2
0
        public void Handle(AccountCheckDepositedEvent message)
        {
            var depositDate = message.CreditDate.AddDays(1);

            while (!(depositDate.DayOfWeek >= DayOfWeek.Monday && depositDate.DayOfWeek <= DayOfWeek.Friday))
            {
                depositDate = depositDate.AddDays(1);
            }
            if (DateTime.UtcNow.Date >= depositDate.Date)
            {
                balance += (decimal)message.Amount;
            }

            Accounts.First(acct => acct.Id == message.AccountId.ToString()).Balance = balance;
            redraw();
        }
        public void Credit(decimal amount, string type, CorrelatedMessage source)
        {
            if (amount <= 0)
            {
                throw new ValidationException("Cannot deposit a negative amount");
            }

            if (type.ToLower().Contains("cash"))
            {
                var cashDeposited = new AccountCashDepositedEvent(source)
                {
                    AccountId = Id,
                    Amount    = amount
                };
                Raise(cashDeposited);
                if (State.ToLower() == "blocked" && Balance >= 0)
                {
                    var unblocked = new AccountUnblockedEvent(source)
                    {
                        AccountId    = Id,
                        AccountState = "Active"
                    };
                    Raise(unblocked);
                }
            }
            else if (type.ToLower().Contains("check"))
            {
                var checkDeposited = new AccountCheckDepositedEvent(source)
                {
                    AccountId  = Id,
                    Amount     = amount,
                    CreditDate = DateTime.UtcNow
                };
                Raise(checkDeposited);
                if (State.ToLower() == "blocked" && Balance >= 0)
                {
                    var unblocked = new AccountUnblockedEvent(source)
                    {
                        AccountId    = Id,
                        AccountState = "Active"
                    };
                    Raise(unblocked);
                }
            }
        }