Business rule question

Business rule question

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


albruan posted on Saturday, December 20, 2008

I have a question about a use case.  I'm dealing with a cataloging system for books and one use case is such that the user is required to enter either the book's ISBN or the author and the title prior to performing a look-up and saving the business class to the database.

I am overriding the AddBusinessRules method and have the title and author properties as dependent properties of each other via the isBidirectional argument being set to true.  If either property contains a value, I'm validating that the other property similarly contains a value; additionally, I perform checks to make sure they don't exceed the length set for their fields in the database.  The thing is I don't have to perform any of the above checks if the user has made an entry for the ISBN; all I have to do in that instance is validate that the entry is a correct entry for an ISBN.  If none of the properties contain a value, the object is deemed to be invalid and thus cannot be saved to the database.

Am I going about improperly overriding the AddBusinessRules method in what I'm attempting?  Is there a better way?

robert_m replied on Sunday, December 21, 2008

Here's what I would do:
- set up bidirectional dependencies between all three properties, ie. between:
-isbn and author
-isbn and title
-author and title

- then use the same method to validate all these three properties (it should check wherher isbn is entered and valid or title and author are both entered etc - all combinations)
- and, of course, you need length checks which can be separate validation rules

Copyright (c) Marimer LLC