private string GetInsertCommandText(AuditEvent auditEvent)
 {
     return(string.Format("INSERT INTO {0} ([{1}]) OUTPUT CONVERT(NVARCHAR(MAX), INSERTED.[{2}]) AS [Id] VALUES (@json)",
                          GetFullTableName(auditEvent),
                          JsonColumnNameBuilder.Invoke(auditEvent),
                          IdColumnNameBuilder.Invoke(auditEvent)));
 }
Exemple #2
0
        private string GetSelectCommandText(AuditEvent auditEvent)
        {
            var cmdText = string.Format("SELECT [{0}] As [Id] FROM {1} WHERE [{2}] = @eventId",
                                        JsonColumnNameBuilder.Invoke(auditEvent),
                                        GetFullTableName(auditEvent),
                                        IdColumnNameBuilder.Invoke(auditEvent));

            return(cmdText);
        }
        private string GetReplaceCommandText(AuditEvent auditEvent)
        {
            var ludScript = LastUpdatedDateColumnNameBuilder != null?string.Format(", [{0}] = GETUTCDATE()", LastUpdatedDateColumnNameBuilder.Invoke(auditEvent)) : string.Empty;

            var cmdText = string.Format("UPDATE {0} SET [{1}] = @json{2} WHERE [{3}] = @eventId",
                                        GetFullTableName(auditEvent), JsonColumnNameBuilder.Invoke(auditEvent), ludScript, IdColumnNameBuilder.Invoke(auditEvent));

            return(cmdText);
        }
Exemple #4
0
        private string GetColumnsForInsert(AuditEvent auditEvent)
        {
            var columns        = new List <string>();
            var jsonColumnName = JsonColumnNameBuilder?.Invoke(auditEvent);

            if (jsonColumnName != null)
            {
                columns.Add(jsonColumnName);
            }
            if (CustomColumns != null)
            {
                foreach (var column in CustomColumns)
                {
                    columns.Add(column.Name);
                }
            }
            return(string.Join(", ", columns.Select(c => $"[{c}]")));
        }
Exemple #5
0
        private string GetSetForUpdate(AuditEvent auditEvent)
        {
            var jsonColumnName = JsonColumnNameBuilder?.Invoke(auditEvent);
            var ludColumn      = LastUpdatedDateColumnNameBuilder?.Invoke(auditEvent);
            var sets           = new List <string>();

            if (jsonColumnName != null)
            {
                sets.Add($"[{jsonColumnName}] = @json");
            }
            if (ludColumn != null)
            {
                sets.Add($"[{ludColumn}] = GETUTCDATE()");
            }
            if (CustomColumns != null && CustomColumns.Any())
            {
                for (int i = 0; i < CustomColumns.Count; i++)
                {
                    sets.Add($"[{CustomColumns[i].Name}] = @c{i}");
                }
            }
            return(string.Join(", ", sets));
        }