コード例 #1
0
        private void AuditHandle()
        {
            var modifiedEntities = ChangeTracker.Entries <EntityTenant>()
                                   .Where(p => p.State == EntityState.Modified).ToList();

            foreach (var entry in modifiedEntities)
            {
                var entityType = entry.Context.Model.FindEntityType(entry.Entity.GetType());
                var audit      = new DtoEntityAudit {
                    EntityName = entityType.Name, EntityId = entry.Entity.Id
                };
                foreach (var prop in entry.OriginalValues.Properties)
                {
                    var originalValue = entry.OriginalValues[prop];
                    var currentValue  = entry.CurrentValues[prop];
                    if (IsNotEqualAndExitAttr(originalValue, currentValue, prop.PropertyInfo))
                    {
                        audit.PropertyAudits.Add(new DtoPropertyAudit
                        {
                            PropertyName = prop.Name,
                            OldValue     = originalValue,
                            NewValue     = currentValue,
                        });
                    }
                }
                AuditList.Add(audit);
            }
        }
コード例 #2
0
 public ItemDetail(Item item, AuditList auditList)
 {
     this.Id           = item.Id;
     this.Name         = item.Name;
     this.Description  = item.Description;
     this.Completed    = item.Completed;
     this.AuditRecords = auditList?.ItemsList ?? new List <AuditRecord>();
 }
コード例 #3
0
        /// <summary>
        /// Fetch audit records from the document database matching the search term
        /// </summary>
        /// <param name="targetType">audit target type</param>
        /// <param name="targetId">audit target id</param>
        /// <param name="searchTerm">search term </param>
        /// <param name="pageSize">number of records to return</param>
        /// <param name="continuationToken">Continuous token string for the next page.</param>
        /// <returns>return AuditList object</returns>
        public async Task <AuditList> RetrieveAuditListAsync(
            string targetType,
            string targetId,
            string searchTerm,
            int pageSize,
            string continuationToken)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(targetType));
            Contract.Requires(!string.IsNullOrWhiteSpace(targetId));
            Guard.AgainstNullArgument(nameof(targetType), targetType);
            Guard.AgainstNullArgument(nameof(targetId), targetId);
            Contract.EndContractBlock();

            var paramterCollection = new SqlParameterCollection(
                new SqlParameter[]
            {
                new SqlParameter {
                    Name = "@TargetType", Value = targetType
                },
                new SqlParameter {
                    Name = "@TargetId", Value = targetId
                }
            });
            AuditList auditList = new AuditList();

            var sqlQuery = "SELECT a.id, a.EventType, a.Timestamp, a.DataType, a.Description, a.UserId, " +
                           "a.UserName, a.UserEmail, a.OperationType  FROM audits a WHERE  a.PartitionKey = CONCAT(@TargetType,'-', @TargetId)";

            // If the search term is not null add the search term also in the where
            if (searchTerm != null)
            {
                sqlQuery += "  AND (CONTAINS(UPPER(a.UserName), UPPER(@SearchTerm)) OR CONTAINS(UPPER(a.EventType), UPPER(@SearchTerm)) )";
                paramterCollection.Add(new SqlParameter {
                    Name = "@SearchTerm", Value = searchTerm
                });
            }

            sqlQuery += " ORDER BY a.Timestamp DESC";
            var querySpec = new SqlQuerySpec(sqlQuery, paramterCollection);

            var collectionLink        = UriFactory.CreateDocumentCollectionUri(DatabaseId, CollectionId);
            var results               = new List <AuditRecord>();
            var nextContinuationToken = string.Empty;

            using (var client = new DocumentClient(new Uri(this.accountEndpoint), this.accountKey))
            {
                IDocumentQuery <AuditRecord> query = client.CreateDocumentQuery <AuditRecord>(
                    collectionLink,
                    querySpec,
                    new FeedOptions
                {
                    MaxItemCount        = pageSize,
                    RequestContinuation = continuationToken,
                    PartitionKey        = new PartitionKey(targetType + "-" + targetId)
                }).AsDocumentQuery();

                if (query.HasMoreResults)
                {
                    var result = await query.ExecuteNextAsync <AuditRecord>();

                    nextContinuationToken = result.ResponseContinuation;
                    results.AddRange(result);
                }

                auditList.ItemsList         = results;
                auditList.ContinuationToken = nextContinuationToken;
            }

            return(auditList);
        }