I am using ASP.NET MVC 2 with nhibernate. I have this Sales class. Sales has many Payments. Sales' payments should not be modified once the sales' status becomes confirmed. I need suggestions on how to enforce this.
I'm stumped on several things when trying to put this validations:
- For adding and deleting payments:
- I can create AddPayment and DeletePayment methods in Sales, but everybody must remember to use these instead of adding and deleting the payments collection directly
- I don't want to hide the payments collection because nhibernate needs it, also this collection is used in other parts of the software
- For modifying existing payments:
- I don't think I should put the validation in the Payments setters because nhibernate needs to access the setters.
- Should I throw exception? There's a discussion about the disadvantages of throwing exception to prevent object entering invalid state. In my case object state after modification may still be valid, but I want to block the modification. Is throwing exception reasonable in this case? What are the alternatives?
Should I enforce this in the controller actions?