public virtual void OnUpdating(object entity, EntityModel model, object currentUser) { var userOptions = ColumnOptions.ModifyUser; var dateOptions = ColumnOptions.ModifyDate; foreach (var propertyItem in model.Map.Properties) { if ((propertyItem.Options & userOptions) != ColumnOptions.None) { model.SetValue(entity, propertyItem.Accessors, currentUser); } else if ((propertyItem.Options & dateOptions) != ColumnOptions.None) { model.SetValue(entity, propertyItem.Accessors, DateTime.Now); } } }
public virtual void OnInserting(object entity, EntityModel model, object currentUser) { var currentDate = DateTime.Now; var userOptions = ColumnOptions.CreateUser | ColumnOptions.ModifyUser; var dateOptions = ColumnOptions.CreateDate | ColumnOptions.ModifyDate; foreach (var propertyItem in model.Map.Properties) { if ((propertyItem.Options & userOptions) != ColumnOptions.None) { model.SetValue(entity, propertyItem.Accessors, currentUser); } else if ((propertyItem.Options & dateOptions) != ColumnOptions.None) { model.SetValue(entity, propertyItem.Accessors, currentDate); } else if ((propertyItem.Options & ColumnOptions.SoftDelete) == ColumnOptions.SoftDelete) { model.SetValue(entity, propertyItem.Accessors, true); } } }