.netTiers
Help Wanted! If you are using .netTiers and find it as invaluable as we do, please consider giving back to the .netTiers team by helping with our effort to fully document .netTiers. To help, simply create an account and you will then be able to edit this wiki.
There are times when one wants to modify entity or log data before entity is saved or updated to database. This logic can be implemented to EntityProviderBase.cs files EntityProviderBase class by overriding the protected override void OnDataRequesting(CommandEventArgs e) resume help method.

Example: update entitys created and updated timestamps if such properties exists in entity:

        protected override void OnDataRequesting(CommandEventArgs e)
        {
            base.OnDataRequesting(e);

if (e.MethodName.Equals("Insert", StringComparison.CurrentCultureIgnoreCase)) { UpdateCreatedData(e.CurrentEntity, e); UpdateUpdatedData(e.CurrentEntity, e); } else if (e.MethodName.Equals("Update", StringComparison.CurrentCultureIgnoreCase)) { UpdateUpdatedData(e.CurrentEntity, e); }

}

private void UpdateCreatedData(Object entity, CommandEventArgs e) { Type type = entity.GetType();

PropertyInfo createdProp = type.GetProperty("Created"); if (createdProp != null && createdProp.CanWrite) { DateTime now = DateTime.Now; createdProp.SetValue(entity, now, null); e.Command.Parameters["@Created"].Value = now; }

}

private void UpdateUpdatedData(Object entity, CommandEventArgs e) { Type type = entity.GetType();

PropertyInfo updatedProp = type.GetProperty("Updated"); if (updatedProp != null && updatedProp.CanWrite) { DateTime now = DateTime.Now; updatedProp.SetValue(entity, now, null); e.Command.Parameters["@Updated"].Value = now; }

}

ScrewTurn Wiki version 2.0.31.