I am working on my first "real" project with LLBLGen 2.0 and am wondering how others maintain basic row creation/modified DateTime fields. For this project I am using SelfServicing.
I have a method in a helper class:
public static IEntity OnSaveUpdateDateTimeFields(IEntity toSave)
{
if (toSave != null)
{
if (toSave.IsNew)
{
// only update the CreatedDate column once
if (toSave.Fields["CreatedDate"] != null)
{
toSave.SetNewFieldValue("CreatedDate", DateTime.UtcNow);
}
if (toSave.Fields["ModifiedDate"] != null)
{
toSave.SetNewFieldValue("ModifiedDate", DateTime.UtcNow);
}
}
if (toSave.IsDirty)
{
if (toSave.Fields["ModifiedDate"] != null)
{
toSave.SetNewFieldValue("ModifiedDate", DateTime.UtcNow);
}
}
}
return toSave;
}
If I were using Adapter I would override OnBeforeEntitySave to call this, but in SS? I see the OnSave method but I don't see how I can call out to OnSaveUpdateDateTimeFields from there -- and I don't want to have this code duplicated in all my entity objects.
I've read through the reference guide, been through the documentation, and consulted mister Google to no avail. I'm missing how to make this work. I could hoist this call in a validator class but it feels wrong to be changing values there.
Could someone shed some light on what I'm missing?
Thanks!
P.S. The above is not used for concurrency, for that I've got a timestamp column and a concurrency predicate factory.