How would I handle this in Stateless

1,049 views
Skip to first unread message

Charles Cherry

unread,
Jun 28, 2011, 4:17:41 PM6/28/11
to dotnet-state-ma...@googlegroups.com
I have a situation where a document needs multiple approvals before it can move to the next state, however, a person in a certain role can override the need for the additional approvals and move the document to the next state. If a person is not in the elevated role, and additional approvals are needed, the document's state needs to remain in a pending status.

When a person clicks an "approve" button, I need the workflow to decide what to do based on the above criteria.

I understand I can use the .PermitIf() to check whether the user is in a role, and whether there are more approvals needed. What I don't understand is how to keep the status at "pending" if there are additional approvals needed and the user is not in the elevated role.

When I set the Permit() method to keep the status the same, I got an error telling me to use Ignore() or PermitReentry(). When I used Ignore(), I got an error stating that I had multiple permitted exit transitions.

So how to handle something like this? The following doesn't work:

_machine.Configure(State.AgencyPending)
    .PermitIf ( Trigger.Approved, State.GOMBPending, ()=> NoMoreApprovals() || IsAgencyHead() )
    .Permit ( Trigger.Approved, State.AgencyPending )
    .Permit ( Trigger.Denied, State.AgencyDenied );

Nor does this:

_machine.Configure(State.AgencyPending)
    .PermitIf ( Trigger.Approved, State.GOMBPending, ()=> NoMoreApprovals() || IsAgencyHead() )
    .Ignore ( Trigger.Approved )
    .Permit ( Trigger.Denied, State.AgencyDenied );

Thanks

Nicholas Blumhardt

unread,
Jun 28, 2011, 7:32:24 PM6/28/11
to dotnet-state-ma...@googlegroups.com
Hi Charles,

Triggers need to be mutually exclusive, so both Trigger.Approved configurations need to use PermitIf, i.e.:

_machine.Configure(State.AgencyPending)
    .PermitIf ( Trigger.Approved, State.GOMBPending, ()=> NoMoreApprovals() || IsAgencyHead() )
    .PermitIf ( Trigger.Approved, State.AgencyPending, ()=> (!NoMoreApprovals() || IsAgencyHead()))
    .Permit ( Trigger.Denied, State.AgencyDenied );

Cheers,
Nick
Reply all
Reply to author
Forward
0 new messages