1

I'm developing an Asp.Net WebApi Application. Now I'm trying to implement state machine in my application using Stateless 3.0 library.

1. Model Class

Model will have a State property, and state change logic in the model class. Once State is changed the model will be updated in client side, and an update request will be sent to server to make changes in Database.

2. WebApi Controller

Model will have a State property, and state change logic in the controller class. A WebApi action called ChangeState() will be called from client side, so the model will be updated in the serverside and saved into database.

PS. I'm using Odata V4.

Question 1:

What is the best method to follow? Any other suggestion? (I'm new to Stateless)

Question 2:

Can I implement state machine logic in a Static class? Is that a good idea?

Question 3:

How can I give custom state error messages to the end user?

Ex: Invoice cannot be 'Authorized' when it's in 'Cancelled' state.

Highly appreciated if anyone can provide a sample code.

Community
  • 1
  • 1
Rahul
  • 2,431
  • 3
  • 35
  • 77
  • 2
    You never change the state from outside, instead you call a trigger and that maybe will change the state. There are some examples how using the statemachine that should also explain state/trigger – Sir Rufo Apr 19 '17 at 10:25
  • Thanks @SirRufo. Could you please send an example? – Rahul Apr 19 '17 at 18:58
  • 1
    The examples can be found at the project home on github – Sir Rufo Apr 19 '17 at 19:25

0 Answers0