public void SetInsertDefaults(object o, ISessionData session) { if (o is ICreateDate) { ((ICreateDate)o).CreateDate = DateTime.UtcNow; } if (o is ICreatorIp) { ((ICreatorIp)o).CreatorIp = session.GetUserIP(); } if (o is ICreatorId) { ((ICreatorId)o).CreatorId = session.UserID; } if (o is IModifyNr) { ((IModifyNr)o).ModifyNr = 1; } if (o is IModifyDate) { ((IModifyDate)o).ModifyDate = DateTime.UtcNow; } if (o is IModifierIp) { ((IModifierIp)o).ModifierIp = session.GetUserIP(); } if (o is IModifierId) { ((IModifierId)o).ModifierId = session.UserID; } }
public async Task SetUpdateDefaultsAsync(DbEntityEntry entity, ISessionData session) { object o = entity.Entity; if (!saveWithStoredProcs && (o is ICreateDate || o is ICreatorIp || o is ICreatorId || o is IModifyNr)) { var original = await entity.GetDatabaseValuesAsync(); if (o is ICreateDate) { ((ICreateDate)o).CreateDate = original.GetValue <DateTime>("CreateDate"); } if (o is ICreatorIp) { ((ICreatorIp)o).CreatorIp = original.GetValue <string>("CreatorIp"); } if (o is ICreatorId) { ((ICreatorId)o).CreatorId = original.GetValue <string>("CreatorId"); } if (o is IModifyNr) { ((IModifyNr)o).ModifyNr = original.GetValue <int>("ModifyNr") + 1; } } if (o is IModifyDate) { ((IModifyDate)o).ModifyDate = DateTime.UtcNow; } if (o is IModifierIp) { ((IModifierIp)o).ModifierIp = session.GetUserIP(); } if (o is IModifierId) { ((IModifierId)o).ModifierId = session.UserID; } }