I am working on my first asp.net mvc web application. I have a form that can be in 14 different states and depending of the current state, transition to other states are or are not possible. There is an average of 3-5 differents possible next state for each current state.
What I need to do now is trigger actions during some state transition. Depending on the initial state and the final states, some actions are trigged (emails are sent for example).
I started this by using switch statements:
switch ((int)currentState)
{
//Initial
case -1:
{
switch ((int)nextState)
{
//Next state: Inv. is waiting
case 1:
{
//Send email to x
emailHelper.Send(x,msg)
//Send email to Y
emailHelper.Send(y,anotherMsg)
}
case 2:
{
doSomethingelse()
}
break;
}
break;
}
//Inv is waiting
case 1:
{
switch ((int)nextState)
{
...
}
}
...
I think this solution would work fine for me, but I am wondering if I could use something better..Any suggestions?
Statebase class orIStateinterface and a derived class for each actual state. Something like the first diagram here. - itsme86ConcreteStateand its responsibilities. - itsme86