I am looking for best practices in applying business logic to form elements in an ASP.NET MVC application. I assume the concepts would apply to most MVC patterns. The goal is to have all the business logic stem from the same place.
I have a basic form with four elements:
Textbox: for entering data
Checkbox: for staff approval
Checkbox: for client approval
Button: for submitting form
The textbox and two check boxes are fields in a database accessed using LINQ to SQL. What I want to do is put logic around the check boxes on who can check them and when.
True table (little silly but it's 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, staff and client; a person's role determines who they are, the roles are maintained in the database along with current state of the check boxes.
So I can simply store the users roll in the view class and enable and disable check boxes based on their role, but this doesn't seem proper. That is putting logic in UI to control which actions can be taken.
How do I get most of this control down into the model? I mean I need to control which check boxes are enabled and then check the results in the model when the form is posted, so it seems the best place for it to originate.
I am looking for a good approach to constructing this, something to follow as I build the application. If you know of some great references which explain these best practices that is really appreciated too.