From 4e6fe6c61f86f5272b40e72309fad9fe68c6c76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87otur?= Date: Fri, 27 Mar 2020 22:49:45 +0300 Subject: [PATCH] Update MongoAuditLogRepository.cs --- .../MongoDB/MongoAuditLogRepository.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs index a813ada669..d2e002fbbe 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs @@ -155,9 +155,11 @@ namespace Volo.Abp.AuditLogging.MongoDB { var query = GetEntityChangeListQuery(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, includeDetails); - return await query.OrderBy(sorting ?? "changeTime desc").As>() - .PageBy>(skipCount, maxResultCount) + var auditLogs = await query.OrderBy(sorting ?? "changeTime desc").As>() + .PageBy>(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); + + return auditLogs.SelectMany(x => x.EntityChanges).ToList(); } public virtual async Task GetEntityChangeCountAsync( @@ -170,13 +172,13 @@ namespace Volo.Abp.AuditLogging.MongoDB CancellationToken cancellationToken = default) { var query = GetEntityChangeListQuery(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName); - var count = await query.As>() + var count = await query.As>() .LongCountAsync(GetCancellationToken(cancellationToken)); return count; } - protected virtual IQueryable GetEntityChangeListQuery( + protected virtual IQueryable GetEntityChangeListQuery( Guid? auditLogId = null, DateTime? startTime = null, DateTime? endTime = null, @@ -185,16 +187,14 @@ namespace Volo.Abp.AuditLogging.MongoDB string entityTypeFullName = null, bool includeDetails = false) { - return null; - // TODO: Learn How to? return GetMongoQueryable() - .WhereIf(auditLogId.HasValue, e => e.AuditLogId == auditLogId) - .WhereIf(startTime.HasValue, e => e.ChangeTime >= startTime) - .WhereIf(endTime.HasValue, e => e.ChangeTime <= endTime) - .WhereIf(changeType.HasValue, e => e.ChangeType == changeType) - .WhereIf(!string.IsNullOrWhiteSpace(entityId), e => e.EntityId == entityId) - .WhereIf(!string.IsNullOrWhiteSpace(entityTypeFullName), - e => e.EntityTypeFullName == entityTypeFullName); + .WhereIf(auditLogId.HasValue, e => e.Id == auditLogId) + .WhereIf(startTime.HasValue, e => e.EntityChanges.Any(ec => ec.ChangeTime >= startTime)) + .WhereIf(endTime.HasValue, e => e.EntityChanges.Any(ec => ec.ChangeTime >= endTime)) + .WhereIf(changeType.HasValue, e => e.EntityChanges.Any(ec => ec.ChangeType >= changeType)) + .WhereIf(!string.IsNullOrWhiteSpace(entityId), e => e.EntityChanges.Any(ec => ec.EntityId == entityId)) + .WhereIf(!string.IsNullOrWhiteSpace(entityTypeFullName), + e => e.EntityChanges.Any(ec => ec.EntityTypeFullName == entityTypeFullName)); } } }