/// <summary> /// Audit the status. /// </summary> /// <param name="context">The <see cref="HttpContext"/></param> /// <param name="typer">The auditlog type.</param> /// <param name="cid">The contest id.</param> /// <param name="username">The username.</param> /// <param name="action">The action name.</param> /// <param name="target">The target name.</param> /// <param name="extra">The extra info.</param> /// <returns>A task representing the audit process.</returns> public static Task AuditAsync(this HttpContext context, AuditlogType typer, int?cid, string username, string action, string?target, string?extra = null) { return(context.RequestServices.GetRequiredService <IAuditlogger>() .LogAsync(typer, username, DateTimeOffset.Now, action, target, extra, cid)); }
/// <inheritdoc /> public Task LogAsync( AuditlogType type, string userName, DateTimeOffset now, string action, string?target, string?extra, int?cid) { Auditlogs.Add(new Auditlog { Action = action, Time = now, DataId = target, DataType = type, ContestId = cid, ExtraInfo = extra, UserName = userName, }); return(Context.SaveChangesAsync()); }
public Task LogAsync(AuditlogType type, string userName, DateTimeOffset now, string action, string?target, string?extra, int?cid) { return(Task.CompletedTask); }
/// <summary> /// Instantiate an <see cref="AuditPointAttribute"/>. /// </summary> /// <param name="type">The auditlog type.</param> public AuditPointAttribute(AuditlogType type) => _type = type;
public AuditlogBuilder <T> WithProperty(Expression <Func <T, bool> > expression, AuditlogType type = AuditlogType.YesNo, Func <bool, string> customFormatter = null) { _actions.Add(new Action(() => WithPropertyInternal(expression, type, customFormatter ?? AuditlogFormatters.BooleanFormatter))); return(this); }
public AuditlogBuilder <T> WithProperty(Expression <Func <T, long> > expression, AuditlogType type = AuditlogType.Number, Func <long, string> customFormatter = null) { _actions.Add(new Action(() => WithPropertyInternal(expression, type, customFormatter ?? AuditlogFormatters.NumberFormatter))); return(this); }
public AuditlogBuilder <T> WithProperty(Expression <Func <T, DateTime?> > expression, AuditlogType type = AuditlogType.DateTime, Func <DateTime?, string> customFormatter = null) { _actions.Add(new Action(() => WithPropertyInternal(expression, type, customFormatter ?? AuditlogFormatters.DateFormatter))); return(this); }
public AuditlogBuilder <T> WithProperty <T2>(Expression <Func <T, IList <T2> > > expression, string propertyName = null, AuditlogType type = AuditlogType.Text, Func <IList <T2>, string> customFormatter = null) { _actions.Add(new Action(() => WithPropertyInternal(expression, type, customFormatter ?? AuditlogFormatters.ListFormatter, propertyName))); return(this); }
private void WithPropertyInternal <T2>(Expression <Func <T, T2> > expression, AuditlogType type, Func <T2, string> formatter, string propertyName = null) { propertyName ??= GetPropertyName(expression); T2 currentValue = _current != null?expression.Compile()(_current) : default; T2 previousValue = _previous != null?expression.Compile()(_previous) : default; var status = GetAuditlogStatus(currentValue, previousValue); if (status != AuditlogStatus.Unchanged) { var item = new AuditlogItem { PropertyName = propertyName, Type = type, Status = status, CurrentValueAsString = formatter(currentValue), PreviousValueAsString = formatter(previousValue), }; _auditlogItems.Add(item); } }