private bool Execute(OpenNewAccountCommand command) { //this spec is part of Akkatecture var spec = new AggregateIsNewSpecification(); if (spec.IsSatisfiedBy(this)) { var aggregateEvent = new AccountOpenedEvent(command.OpeningBalance); Emit(aggregateEvent); } return(true); }
public Account OpenNewAccount(OpenNewAccountCommand command) { // validate user input ... Validate(command); // load bank account from the database var accountToWithdrawGift = _dbContext.Accounts.Single(a => a.Name == "Bank Ldt."); const decimal giftAmount = 400.00M; // call domain service to execute the business case var newAccount = _domainService.OpenNewAccount(command.Name, accountToWithdrawGift, giftAmount); // persist new Account in the Database _dbContext.Accounts.Add(newAccount); _dbContext.SaveChanges(); return(newAccount); }
public static async Task Main(string[] args) { //initialize actor system CreateActorSystem(); //create send receiver identifiers var senderId = AccountId.New; var receiverId = AccountId.New; //create mock opening balances var senderOpeningBalance = new Money(509.23m); var receiverOpeningBalance = new Money(30.45m); //create commands for opening the sender and receiver accounts var openSenderAccountCommand = new OpenNewAccountCommand(senderId, senderOpeningBalance); var openReceiverAccountCommand = new OpenNewAccountCommand(receiverId, receiverOpeningBalance); //send the command to be handled by the account aggregate AccountManager.Tell(openReceiverAccountCommand); AccountManager.Tell(openSenderAccountCommand); //create command to initiate money transfer var amountToSend = new Money(125.23m); var transaction = new Transaction(senderId, receiverId, amountToSend); var transferMoneyCommand = new TransferMoneyCommand(senderId, transaction); //send the command to initiate the money transfer AccountManager.Tell(transferMoneyCommand); //fake 'wait' to let the saga process the chain of events await Task.Delay(TimeSpan.FromSeconds(1)); Console.WriteLine("Walkthrough operations complete.\n\n"); Console.WriteLine("Press Enter to get the revenue:"); Console.ReadLine(); //get the revenue stored in the repository var revenue = RevenueRepository.Ask <RevenueReadModel>(new GetRevenueQuery(), TimeSpan.FromMilliseconds(500)).Result; //print the results Console.WriteLine($"The Revenue is: {revenue.Revenue.Value}."); Console.WriteLine($"From: {revenue.Transactions} transaction(s)."); Console.ReadLine(); }
private void NewAccount_Click(object sender, RoutedEventArgs e) { try { var li = new LoginInfo("", "", true); if (OpenNewAccountCommand != null) { OpenNewAccountCommand.Execute(li); if (!li.Canceled) { this.TradingAccount = li.Account; this.TradingPassword = li.Password; this.TradingDemo = li.IsDemo; } } } catch (Exception exc) { masterModel.Log = exc; } }