private void ChangeState(CustomerState dest) { var command = GetCommand(CustomerTransition.Create(State, dest)); if (command == null) { throw new Exception($"Command is null for {State} -> {dest}"); } command.Execute(); }
public CustomerService() { RegisterTransition(CustomerTransition.Create(CustomerState.Undefined, CustomerState.New), new UndefinedToNewCommand()); RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Confirmed), new NewToConfirmedCommand()); RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Unconfirmed), new NewToUnconfirmedCommand()); }
public void ChangeStateToUnconfirmed() { var transition = new CustomerTransition(State, CustomerState.Unconfirmed); if (!HasTransition(transition)) { throw new InvalidOperationException(transition.ToString()); } if (DocumentsSigned) { throw new Exception("Documents are signed!"); } State = CustomerState.Unconfirmed; }
public Customer(Guid customerId) { CustomerId = customerId; State = CustomerState.Undefined; RegisterTransition(CustomerTransition.Create(CustomerState.Undefined, CustomerState.New), new UndefinedToNewCommand(this)); RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Confirmed), new NewToConfirmedCommand(this)); RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Unconfirmed), new NewToUnconfirmedCommand(this)); ChangeStateToNew(); }
private void ChangeState(Customer customer, CustomerState dest) { if (customer == null) { throw new ArgumentNullException(nameof(customer)); } var command = GetCommand(CustomerTransition.Create(customer.State, dest)); if (command == null) { throw new Exception($"Command is null for {customer.State} -> {dest}"); } var baseCustomerCommand = (BaseCustomerCommand)command; baseCustomerCommand.SetCustomer(customer); command.Execute(); }