Esempio n. 1
0
        private void Handle(Withrowal cmd)
        {
            var sender = Sender;

            if (cmd.From != _state.AccountNumber)
            {
                throw new NotFoundException("Invalid Account Number");
            }

            if (cmd.Amount <= 0)
            {
                throw new ValidationException("Withrowal Amount need to be positive value.");
            }

            if (cmd.Amount > _state.AvailableBalance)
            {
                throw new ValidationException("Insuficient funds");
            }

            var withrowal = new AccountDebited
            {
                TransactionId = cmd.TransactionId,
                From          = _state.AccountNumber,
                Amount        = cmd.Amount,
                CurrencyDate  = DateTime.UtcNow,
                To            = cmd.To
            };

            Persist(withrowal, e =>
            {
                ApplyEvent(e);
                Respond(sender, "Ok", new[] { withrowal });
            });
        }
Esempio n. 2
0
        private void Test(IActorRef accounts)
        {
            var acc1          = "1";
            var acc2          = "2";
            var transactionId = Guid.NewGuid().ToString();

            var create1 = new CreateAccount
            {
                AccountNumber  = acc1,
                InitialBalance = 0
            };

            AppAkkaRefs
            .Cluster
            .Scheduler
            .ScheduleTellOnce(
                TimeSpan.FromSeconds(5),
                accounts,
                new CommandEnvelope(acc1, create1),
                ActorRefs.Nobody);



            var create2 = new CreateAccount
            {
                AccountNumber  = acc2,
                InitialBalance = 1000
            };

            AppAkkaRefs
            .Cluster
            .Scheduler
            .ScheduleTellOnce(
                TimeSpan.FromSeconds(7),
                accounts,
                new CommandEnvelope(acc2, create2),
                ActorRefs.Nobody);


            var withrowal = new Withrowal
            {
                Amount        = 10,
                From          = acc2,
                To            = acc1,
                TransactionId = transactionId
            };

            AppAkkaRefs
            .Cluster
            .Scheduler
            .ScheduleTellOnce(
                TimeSpan.FromSeconds(12),
                accounts,
                new CommandEnvelope(acc2, withrowal),
                ActorRefs.Nobody);

            /*
             * var deposit = new Deposit
             * {
             *  Amount = 10,
             *  CurrencyDate = DateTime.UtcNow,
             *  From = acc2,
             *  To = acc1,
             *  TransactionId = transactionId
             * };
             * AppAkkaRefs
             *      .Cluster
             *      .Scheduler
             *      .ScheduleTellOnce(
             *          TimeSpan.FromSeconds(13),
             *          accounts,
             *          new CommandEnvelope(acc1, deposit),
             *          ActorRefs.Nobody);
             *
             * var commit = new CommitTransaction
             * {
             *  AccountNumber = acc2,
             *  TransactionId = transactionId
             * };
             * AppAkkaRefs
             *      .Cluster
             *      .Scheduler
             *      .ScheduleTellOnce(
             *          TimeSpan.FromSeconds(14),
             *          accounts,
             *          new CommandEnvelope(acc2, commit),
             *          ActorRefs.Nobody);
             */
        }