private void Handle(ICommandContext commandContext, StartTransaction command) { if (AvailableBalance <= command.Amount) { throw new Exception("Insufficion founds"); } if (AccountNumber != command.FromAccount) { throw new Exception("Wrong account number"); } if (command.Amount <= 0) { return; } if (OutstandingTransactions.ContainsKey(command.TransactionId)) { return; } commandContext.Emit(new AccountDebited { CausationId = command.CausationId, Amount = command.Amount, ToAccount = command.ToAccount, TransactionId = command.TransactionId, AccuontNumber = command.FromAccount }); }
private void Handle(ICommandContext commandContext, CreateAccount command) { if (!string.IsNullOrEmpty(AccountNumber)) { return; } commandContext.Emit(new AccountCreated { AccountNumber = command.AccountNumber, CausationId = command.CausationId }); if (command.InitialBalance > 0) { commandContext.Emit(new AccountBalanceInitialized { Balance = command.InitialBalance, CausationId = command.CausationId, AccuuntNumber = command.AccountNumber }); } }
private void Handle(ICommandContext commandContext, CommitTransaction command) { if (AccountNumber != command.AccountNumber) { throw new Exception("Wrong account number"); } commandContext.Emit( new TransactionCommitted { AccountNumber = command.AccountNumber, CausationId = command.CausationId, TransactionId = command.TransactionId }); }
public Empty AddItem(Com.Example.Shoppingcart.AddLineItem item, ICommandContext ctx) { if (item.Quantity <= 0) { ctx.Fail("Cannot add negative quantity of to item" + item.ProductId); } ctx.Emit( new ItemAdded() { Item = new LineItem() { ProductId = item.ProductId, Quantity = item.Quantity } } ); return(new Empty()); }
private void Handle(ICommandContext commandContext, Deposit command) { if (AccountNumber != command.ToAccount) { throw new Exception("Wrong account number"); } if (command.Amount <= 0) { return; } if (!OutstandingTransactions.ContainsKey(command.TransactionId)) { return; } commandContext.Emit(new AccountCredited { AccountNumber = command.ToAccount, Amount = command.Amount, CausationId = command.CausationId, FromAccount = command.FromAccount, TransactionId = command.TransactionId }); }
public Wrapped AddItem(string msg, ICommandContext context) { Assert.Equal("AddItem", context.CommandName); context.Emit(msg + " event"); return(new Wrapped(msg)); }