Step 3: Grouping Transitions and Adding Conditions to Transitions

In this step, you will group transitions and add a condition to each transition.

To specify the conditions you defined in Step 1: Adding a Condition Pack, do the following:

  1. In the lambda expression provided for the WithTransitions method, define a group of transitions, as the following code shows.
                        .WithTransitions(transitions =>
                        {
                            transitions.AddGroupFrom<States.onHold>(ts =>
                            {
                            });
                        })

    In the code above, you have defined a group of transitions whose initial state is OnHold.

  2. Move the definition of the transition that you added in Step 1: Defining a Transition inside the group, and remove the call of the From method because it is no longer necessary. The resulting code is shown below.
                            transitions.AddGroupFrom<States.onHold>(ts =>
                            {
                                ts.Add(t => t.To<States.readyForAssignment>()
                                    .IsTriggeredOn(g => g.ReleaseFromHold)                            );
                            });
  3. After the IsTriggeredOn method call, add the When method call, and specify the DoesNotRequirePrepayment condition, as the following code shows.
                                ts.Add(t => t.To<States.readyForAssignment>()
                                    .IsTriggeredOn(g => g.ReleaseFromHold)
                                    .When(conditions.DoesNotRequirePrepayment));
  4. After this transition, add the new transition from the OnHold state to the PendingPayment state, as the following code shows. Specify the RequiresPrepayment condition.
                                ts.Add(t => t.To<States.pendingPayment>()
                                    .IsTriggeredOn(g => g.ReleaseFromHold)
                                    .When(conditions.RequiresPrepayment));
  5. Save your changes.
The full code of the section should look as follows.
                    .WithTransitions(transitions =>
                    {
                        transitions.AddGroupFrom<States.onHold>(ts =>
                        {
                            ts.Add(t => t.To<States.readyForAssignment>()
                                .IsTriggeredOn(g => g.ReleaseFromHold)
                                .When(conditions.DoesNotRequirePrepayment));
                            ts.Add(t => t.To<States.pendingPayment>()
                                .IsTriggeredOn(g => g.ReleaseFromHold)
                                .When(conditions.RequiresPrepayment));
                        });
                    })