Soft Business Rule

Soft Business Rule

Old forum URL: forums.lhotka.net/forums/t/7303.aspx


jasonlaw posted on Sunday, July 19, 2009

Sometime we may need to have soft business rule that we allow the rule to be broken but instead giving error we give warning, and the data is allowed to be saved into database.
For instance in a package delivery planning system we allow the planner to plan the delivery time late due to many reason. In this case, how should we implement it without hacking the CSLA.NET?

Marjon1 replied on Sunday, July 19, 2009

CSLA has the concept of information / warning based validation rules. I can't remember what version these were introduced in, but do exactly what you want. These require custom validation handlers to be written to handle this and within that method set e.Severity to warning or information, the object will still be valid and you can do checks against the broken rules collection to determine if there are any warning or information rules currently 'broken'.

Depending on how you display error messages, instead of the normal red-cross you can get it to display other icons for the warning/information rules as well, if that is what you want to achieve.

jasonlaw replied on Sunday, July 19, 2009

Thanks, that is what I am looking for.
Btw, are all the broken rules kept in the same broken rules collection? Wouldn't it quite confuse to keep both hard and soft broken rules in the same collection? Can it be separated out to 2 different collections?

Marjon1 replied on Monday, July 20, 2009

All the rules are kept in the same collection, there are methods to get the first warning/information based rule that is broken.

It hasn't caused any confusion in the development work that I've done, but it depends on how you intend to use / interact with the rules. You could possibly split it yourself in a derived class if you really wanted to, but would end up looping through the same rule of broken rules all the time.

RockfordLhotka replied on Monday, July 20, 2009

You can also use simple LINQ queries to filter the list to get items for the specific property and/or severity you need.

Copyright (c) Marimer LLC