private void AuditChanges(string action, Bean bean) { var api = bean.Api; if (!api.DirtyTracking || _auditBlacklist.Contains(bean.GetKind().ToUpper())) { return; } var dirtyBackup = bean.GetDirtyBackup(); var changes = GetChanges(bean); if (action != "DELETE" && !changes.Any()) { return; } var kind = bean.GetKind(); var keyName = api.GetKeyName(kind); if ("INSERT|UPDATE".Contains(action)) { foreach (var change in changes) { var audit = api.Dispense("AUDIT"); audit .Put("AuditDate", DateTime.Now) .Put("Action", action) .Put("User", api.CurrentUser ?? string.Empty) .Put("Object", bean.GetKind()) .Put("ObjectId", bean[keyName]) .Put("Property", change.Key) .Put("PropertyType", api.GetDbTypeFromValue(change.Value)) .Put("OldValue", action == "UPDATE" ? dirtyBackup[change.Key].FormatValueToString() : string.Empty) .Put("NewValue", bean[change.Key].FormatValueToString()) .Put("Notes", string.Empty) .Store(); } } else if (action == "DELETE") { var audit = api.Dispense("AUDIT"); audit .Put("AuditDate", DateTime.Now) .Put("Action", action) .Put("User", api.CurrentUser ?? string.Empty) .Put("Object", bean.GetKind()) .Put("ObjectId", bean[keyName]) .Put("Property", string.Empty) .Put("PropertyType", string.Empty) .Put("OldValue", string.Empty) .Put("NewValue", string.Empty) .Put("Notes", bean.ToJson()); api.Store(audit); } }
private void AuditChanges(string action, Bean bean) { var api = bean.Api; var columns = api.GetKindColumns(bean.GetKind()); if (columns.Count == 0) { return; } if (action == "INSERT") { if (columns.Contains("CreatedBy")) { bean["CreatedBy"] = api.CurrentUser ?? string.Empty; } if (columns.Contains("CreatedAt")) { bean["CreatedAt"] = DateTime.Now; } } if (columns.Contains("ChangedBy")) { bean["ChangedBy"] = api.CurrentUser ?? string.Empty; } if (columns.Contains("ChangedAt")) { bean["ChangedAt"] = DateTime.Now; } }
public static ColumnNotFoundException Create(Bean bean, string column) { var message = $@"The requested column '{column}' for Bean '{bean.GetKind()}' was not found. " + "You can assign a value to the column to create it"; return(new ColumnNotFoundException(message)); }
public override void BeforeInsert(Bean bean) { var kind = bean.GetKind(); var lastKey = bean.Api.Cell <string>(false, $"SELECT MAX({_defaultKey}) FROM {kind}"); bean[_defaultKey] = lastKey == null?GetInitialKey(kind) : GetNextKey(lastKey); }
public static object ReverseBeanKind(Bean aBean, params object[] args) { var chArr = aBean.GetKind().ToCharArray(); Array.Reverse((Array)chArr); return(new string (chArr)); }
public static void MyBeanAction(Bean aBean, params object[] args) { var output = (ITestOutputHelper)args[0]; output.WriteLine($"The Bean is of kind: \"{aBean.GetKind()}\""); output.WriteLine($"Parameter: {args[1]}"); }
public static ColumnNotFoundException New(Bean bean, string column) { string message = String.Format( @"The requested column '{0}' for Bean '{1}' was not found. You can assign a value to the column to create it", column, bean.GetKind()); return(new ColumnNotFoundException(message)); }
public void Kind() { var bean = new Bean("kind1"); Assert.Equal("kind1", bean.GetKind()); }
public bool IsNew(Bean bean) { return(IsNew(bean.GetKind(), bean.Export())); }