I'm looking for best practices for applying business logic to form elements in an ASP.NET MVC application. I guess the concepts will apply to most MVC templates. The goal is for all business logic to be based on the same place.
I have a basic form with four elements:
Text field : for data entry
Flag : for approving staff
Flag : for confirming a client
Button : for submitting a form
A text field and two flags are fields in the database that are accessed using LINQ to SQL. What I want to do is put the logic around the checkboxes on which you can check them and when.
The true table (a little silly, but this is an example):
when checked || may check Staff || may check Client
Staff | Client || Staff | Client || Staff | Client
0 0 || 1 0 0 1
0 1 || 0 0 0 1
1 0 || 1 0 0 1
1 1 || 0 0 0 1
There are two security roles, personnel and customer; the human role determines who they are, the roles are supported in the database along with the current state of the flags.
Therefore, I can just save the users roll in the presentation class and enable and disable the checkboxes based on their role, but this does not seem to be correct. This puts logic in the user interface to control what actions can be taken.
How to get most of this control into a model? I mean, I need to control which checkboxes are enabled, and then check the results in the model when the form is placed, so this seems like the best place to create it.
, - , . - , , .