예제 #1
0
        private void AddAuditInformation(string identityIdentifier)
        {
            NullGuard.NotNullOrWhiteSpace(identityIdentifier, nameof(identityIdentifier));

            foreach (EntityEntry entityEntry in ChangeTracker.Entries())
            {
                AuditModelBase auditModel = entityEntry.Entity as AuditModelBase;
                if (auditModel == null)
                {
                    continue;
                }

                DateTime utcNow = DateTime.UtcNow;
                if (entityEntry.State == EntityState.Added)
                {
                    auditModel.CreatedUtcDateTime   = utcNow;
                    auditModel.CreatedByIdentifier  = identityIdentifier;
                    auditModel.ModifiedUtcDateTime  = utcNow;
                    auditModel.ModifiedByIdentifier = identityIdentifier;
                    continue;
                }

                if (entityEntry.State == EntityState.Modified)
                {
                    auditModel.ModifiedUtcDateTime  = utcNow;
                    auditModel.ModifiedByIdentifier = identityIdentifier;
                }
            }
        }
예제 #2
0
        internal void CopyAuditInformationTo(IAuditable auditable)
        {
            NullGuard.NotNull(auditable, nameof(auditable));

            DateTime createdUtcDateTime  = CreatedUtcDateTime;
            string   createdByIdentifier = CreatedByIdentifier;

            if (createdUtcDateTime > BasicAccount.CreatedUtcDateTime)
            {
                createdUtcDateTime  = BasicAccount.CreatedUtcDateTime;
                createdByIdentifier = BasicAccount.CreatedByIdentifier;
            }

            DateTime modifiedUtcDateTime  = ModifiedUtcDateTime;
            string   modifiedByIdentifier = ModifiedByIdentifier;

            if (modifiedUtcDateTime < BasicAccount.ModifiedUtcDateTime)
            {
                modifiedUtcDateTime  = BasicAccount.ModifiedUtcDateTime;
                modifiedByIdentifier = BasicAccount.ModifiedByIdentifier;
            }

            AuditModelBase lastModifiedInfoModel = GetLastModifiedInfoModel();

            if (lastModifiedInfoModel != null && modifiedUtcDateTime < lastModifiedInfoModel.ModifiedUtcDateTime)
            {
                modifiedUtcDateTime  = lastModifiedInfoModel.ModifiedUtcDateTime;
                modifiedByIdentifier = lastModifiedInfoModel.ModifiedByIdentifier;
            }

            AuditModelBase lastModifiedPostingLineModel = GetLastModifiedPostingLineModel();

            if (lastModifiedPostingLineModel != null && modifiedUtcDateTime < lastModifiedPostingLineModel.ModifiedUtcDateTime)
            {
                modifiedUtcDateTime  = lastModifiedPostingLineModel.ModifiedUtcDateTime;
                modifiedByIdentifier = lastModifiedPostingLineModel.ModifiedByIdentifier;
            }

            auditable.AddAuditInformation(createdUtcDateTime, createdByIdentifier, modifiedUtcDateTime, modifiedByIdentifier);
        }