I have a method to manage records, which have a unique code. I call the method with no parameters. When the method receives no parameter, the subject
When should I be setting the nupdatemode so that my business object validate method knows it is an edit or an add?
Thanks, Doug
In most cases this should be automatic. If you use New()
or Load()
to load or create an entity the value will be set appropriately. When you call Save()
and it succeeds that too should set the value automatically to edit. Any time you save successfully the record is considered 'not new'.
If you need to track the state of the object outside of these very simple situations you have to track it yourself. You can always use the mode as a base and then expand on that when you know the state is changed in an unexpected
way.
+++ Rick ---
But when a duplicate code is entered in the "new" form (after calling method with no parameter), the duplicate code is found (because it already exist) during the Load method (when attempting to save the "new" record) and sets the nupdatemode to 1 (edit). Because it is in edit mode, my validate() method doesn't know it is an attempt to add the record and does not check for a duplicate. It just saves it as an update. When it should reject for duplicate code (pk).
I don't know what you mean by "New Form" - that's a different level of abstraction. If you're feeding values into the business layer that can have dupes you have to verfify those before you save (or potentially before you load if that matters).
If a user enters a new form and enters data for an existing ID there, then you you have to decide how to handle that - there's no way to automatically resolve that in the generic business layer. Your application has to decide whether to:
- Load the data and then overwrite
- Create a new record with new ID
- Create a duplicate ID record (valid in some cases)
Duplicate checking generally can be done in the Validate()
override of your business object.
+++ Rick ---