private async Task AuditLog(int currentUserId, int objectId, object newObject, object priorObject, bool priorObjectAlreadySerialized = false) { if (_auditSet == null) { // audit logging is not enabled return; } var audit = new AuditLog { EntityType = newObject.GetType().ToString(), EntityId = objectId, UpdatedBy = currentUserId, UpdatedAt = DateTime.Now, CurrentValue = _entitySerializer.Serialize(newObject) }; if (priorObject != null) { if (priorObjectAlreadySerialized) { audit.PreviousValue = priorObject.ToString(); } else { audit.PreviousValue = _entitySerializer.Serialize(priorObject); } } await AuditSet.AddAsync(audit); }
public virtual async Task RemoveAsync(int userId, int id) { var entity = await DbSet.FindAsync(id); if (entity == null) { throw new GraException($"{nameof(DomainEntity)} id {id} could not be found."); } DbSet.Remove(entity); if (AuditSet != null) { var audit = new AuditLog { EntityType = entity.GetType().ToString(), EntityId = entity.Id, UpdatedBy = userId, UpdatedAt = _dateTimeProvider.Now, CurrentValue = null, PreviousValue = _entitySerializer.Serialize(entity) }; await AuditSet.AddAsync(audit); } }