protected override bool ReceiveCommand(object message) { if (message is CreateCustomer) { var cmd = (CreateCustomer) message; Id = cmd.CustomerId; var evt = new CustomerCreated { CustomerId = cmd.CustomerId, CustomerName = cmd.CustomerName }; Persist(evt, Create); Sender.Tell(evt.CustomerId, Self); return true; } if (message is ChangeCustomerName) { var cmd = (ChangeCustomerName) message; var evt = new CustomerNameChanged { CustomerId = Id, NewCustomerName = cmd.NewName }; Persist(evt, ChangeName); Sender.Tell(true, Self); return true; } if (message is string) { var cmd = (string) message; if (cmd == "snapshot") { SaveSnapshot(_state); } return true; } return false; }
private void Create(CustomerCreated evt) { Id = evt.CustomerId; Name = evt.CustomerName; }