Example #1
0
        public virtual async Task <List <EntityChange> > GetEntityChangeListAsync(
            string sorting                      = null,
            int maxResultCount                  = 50,
            int skipCount                       = 0,
            Guid?auditLogId                     = null,
            DateTime?startTime                  = null,
            DateTime?endTime                    = null,
            EntityChangeType?changeType         = null,
            string entityId                     = null,
            string entityTypeFullName           = null,
            bool includeDetails                 = false,
            CancellationToken cancellationToken = default)
        {
            var query = GetEntityChangeListQuery(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName);

            var auditLogs = await query.As <IMongoQueryable <AuditLog> >()
                            .PageBy <AuditLog, IMongoQueryable <AuditLog> >(skipCount, maxResultCount)
                            .ToListAsync(GetCancellationToken(cancellationToken));

            // TODO: Improve this specification

            return(auditLogs
                   .SelectMany(x => x.EntityChanges.Where(y =>
                                                          IsSatisfiedEntityChange(y, auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName)))
                   .AsQueryable().OrderBy(sorting ?? "changeTime desc").ToList());
        }
Example #2
0
        public virtual async Task <long> GetEntityChangeCountAsync(
            Guid?auditLogId                     = null,
            DateTime?startTime                  = null,
            DateTime?endTime                    = null,
            EntityChangeType?changeType         = null,
            string entityId                     = null,
            string entityTypeFullName           = null,
            CancellationToken cancellationToken = default)
        {
            var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName);

            var totalCount = await query.LongCountAsync(GetCancellationToken(cancellationToken));

            return(totalCount);
        }
Example #3
0
 protected virtual IQueryable <EntityChange> GetEntityChangeListQuery(
     Guid?auditLogId             = null,
     DateTime?startTime          = null,
     DateTime?endTime            = null,
     EntityChangeType?changeType = null,
     string entityId             = null,
     string entityTypeFullName   = null,
     bool includeDetails         = false)
 {
     return(DbContext.Set <EntityChange>().AsNoTracking().IncludeDetails(includeDetails)
            .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.Contains(entityTypeFullName)));
 }
Example #4
0
 protected virtual async Task <IQueryable <EntityChange> > GetEntityChangeListQueryAsync(
     Guid?auditLogId             = null,
     DateTime?startTime          = null,
     DateTime?endTime            = null,
     EntityChangeType?changeType = null,
     string entityId             = null,
     string entityTypeFullName   = null)
 {
     return((await GetMongoQueryableAsync())
            .SelectMany(x => x.EntityChanges)
            .WhereIf(auditLogId.HasValue, e => e.Id == 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.Contains(entityTypeFullName)));
 }
Example #5
0
 protected virtual IQueryable <AuditLog> GetEntityChangeListQuery(
     Guid?auditLogId             = null,
     DateTime?startTime          = null,
     DateTime?endTime            = null,
     EntityChangeType?changeType = null,
     string entityId             = null,
     string entityTypeFullName   = null)
 {
     return(GetMongoQueryable()
            .Where(x => x.EntityChanges != null)
            .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.Contains(entityTypeFullName))));
 }
Example #6
0
        public virtual async Task <List <EntityChange> > GetEntityChangeListAsync(
            string sorting                      = null,
            int maxResultCount                  = 50,
            int skipCount                       = 0,
            Guid?auditLogId                     = null,
            DateTime?startTime                  = null,
            DateTime?endTime                    = null,
            EntityChangeType?changeType         = null,
            string entityId                     = null,
            string entityTypeFullName           = null,
            bool includeDetails                 = false,
            CancellationToken cancellationToken = default)
        {
            var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, includeDetails);

            return(await query.OrderBy(sorting.IsNullOrWhiteSpace()?(nameof(EntityChange.ChangeTime) + " DESC") : sorting)
                   .PageBy(skipCount, maxResultCount)
                   .ToListAsync(GetCancellationToken(cancellationToken)));
        }
Example #7
0
        protected virtual bool IsSatisfiedEntityChange(
            EntityChange entityChange,
            Guid?auditLogId             = null,
            DateTime?startTime          = null,
            DateTime?endTime            = null,
            EntityChangeType?changeType = null,
            string entityId             = null,
            string entityTypeFullName   = null)
        {
            if (auditLogId != null && auditLogId != entityChange.AuditLogId)
            {
                return(false);
            }

            if (startTime != null && startTime.Value >= entityChange.ChangeTime)
            {
                return(false);
            }

            if (endTime != null && endTime.Value <= entityChange.ChangeTime)
            {
                return(false);
            }

            if (changeType != null && changeType != entityChange.ChangeType)
            {
                return(false);
            }

            if (entityId != null && entityId != entityChange.EntityId)
            {
                return(false);
            }

            if (entityTypeFullName != null && entityChange.EntityTypeFullName.Contains(entityTypeFullName))
            {
                return(false);
            }

            return(true);
        }
        public virtual async Task <List <EntityChange> > GetEntityChangeListAsync(
            string sorting                      = null,
            int maxResultCount                  = 50,
            int skipCount                       = 0,
            Guid?auditLogId                     = null,
            DateTime?startTime                  = null,
            DateTime?endTime                    = null,
            EntityChangeType?changeType         = null,
            string entityId                     = null,
            string entityTypeFullName           = null,
            bool includeDetails                 = false,
            CancellationToken cancellationToken = default)
        {
            var query = await GetEntityChangeListQueryAsync(auditLogId, startTime, endTime, changeType, entityId, entityTypeFullName, cancellationToken);

            return(await query
                   .OrderBy(sorting ?? "changeTime desc")
                   .As <IMongoQueryable <EntityChange> >()
                   .PageBy <EntityChange, IMongoQueryable <EntityChange> >(skipCount, maxResultCount)
                   .ToListAsync(GetCancellationToken(cancellationToken)));
        }
Example #9
0
 public Task <long> GetEntityChangeCountAsync(Guid?auditLogId = null, DateTime?startTime = null, DateTime?endTime = null, EntityChangeType?changeType = null, string entityId = null, string entityTypeFullName = null, CancellationToken cancellationToken = default)
 {
     throw new NotImplementedException();
 }
Example #10
0
 public Task <List <EntityChange> > GetEntityChangeListAsync(string sorting = null, int maxResultCount = 50, int skipCount = 0, Guid?auditLogId = null, DateTime?startTime = null, DateTime?endTime = null, EntityChangeType?changeType = null, string entityId = null, string entityTypeFullName = null, bool includeDetails = false)
 {
     throw new NotImplementedException();
 }