Auditing when entity truly changed

Posts   
 
    
vikramka
User
Posts: 42
Joined: 08-Sep-2004
# Posted on: 12-Aug-2013 13:58:48   

In the UI layer, users will sometimes edit a record and then click save without actually having changed the record. In the service layer or UI layer, code will then update the last_updated_by field with the user's info. The data layer and the audit layer will see that the entity has changed and will update and audit it.

So my question is, how to prevent the saving of a record, if the main fields haven't really changed ?

I guess, in the service layer, we can check to see if the main entity has changed before updating the last_updated_by field. But I want to know if there is a way of doing that in the data layer, which will probably make the service layer a bit cleaner.

Is there a way of saying that some fields are audit fields and aren't really important when considering that the entity has changed? Or perhaps let the audit entity take care of putting in the user's info if the entity has changed, but then how do we pass in the user's info?

If you have pondered or used a particular solution, can you please share it?

Walaa avatar
Walaa
Support Team
Posts: 14986
Joined: 21-Aug-2005
# Posted on: 12-Aug-2013 18:45:05   

In case of updating an entity, Audit is called after the entity is saved.

I think it's better to handle this in the service layer, by just checking entity.IsDirty flag, before proceeding.

Another option is to have this checked and last_update set in a Validator (ValidateEntityBeforeSave).

vikramka
User
Posts: 42
Joined: 08-Sep-2004
# Posted on: 12-Aug-2013 19:24:03   

Walaa wrote:

Another option is to have this checked and last_update set in a Validator (ValidateEntityBeforeSave).

This is a very good suggestion. Thanks.