private async Task RecordAuditTrailEventAsync(string eventName, string username) { if (string.IsNullOrEmpty(username)) { return; } var userManager = GetUserManagerFromHttpContext(); var user = await userManager.FindByNameAsync(username); if (user == null) { var eventData = new Dictionary <string, object> { { "UserName", username } }; await _auditTrailManager.AddAuditTrailEventAsync <UserAuditTrailEventProvider>( new AuditTrailContext(eventName, username, eventData, "user", username)); } else { var eventData = new Dictionary <string, object> { { "UserId", await userManager.GetUserIdAsync(user) }, { "UserName", user.UserName } }; await _auditTrailManager.AddAuditTrailEventAsync <UserAuditTrailEventProvider>( new AuditTrailContext(eventName, user.UserName, eventData, "user", user.UserName)); } }
private async Task RecordAuditTrailEventAsync(string eventName, IContent content) { var buildingAuditTrailEventContext = new BuildingAuditTrailEventContext(content.ContentItem, eventName); await _auditTrailEvents.InvokeAsync((provider, context) => provider.BuildingAuditTrailEventAsync(context), buildingAuditTrailEventContext, Logger); // -1 is a unique contentItem.Id that only Preview is using such that another stored document can't have // the same one in the IContentManagerSession index. if (buildingAuditTrailEventContext.IsCanceled || content.ContentItem.Id == -1) { return; } var versionNumber = await _session.Query <ContentItem, ContentItemIndex>() .Where(contentItemIndex => contentItemIndex.ContentItemId == content.ContentItem.ContentItemId) .CountAsync(); var eventData = new Dictionary <string, object> { { "ContentItem", content.ContentItem }, { "VersionNumber", versionNumber } }; await _auditTrailManager.AddAuditTrailEventAsync <ContentAuditTrailEventProvider>( new AuditTrailContext(eventName, _hca.GetCurrentUserName(), eventData, "content", content.ContentItem.ContentItemId)); }