Example #1
0
        private void WriteKeys(AuditEntryState state)
        {
            var keys = state.EntityType.KeyMembers;

            if (keys == null)
            {
                return;
            }

            var currentValues = state.IsDeleted
                ? state.ObjectStateEntry.OriginalValues
                : state.ObjectStateEntry.CurrentValues;

            foreach (var keyMember in keys)
            {
                var auditkey = new AuditKey();
                try
                {
                    var name = keyMember.Name;
                    auditkey.Name = name;
                    auditkey.Type = GetType(keyMember);

                    object value = currentValues.GetValue(name);
                    value = FormatValue(state, name, value);

                    auditkey.Value = value;
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.Message);
                    auditkey.Value = _errorText;
                }
                state.AuditEntity.Keys.Add(auditkey);
            }
        }
        private void WriteKeys(AuditEntryState state)
        {
            var keys = state.EntityType.KeyMembers;
            if (keys == null)
                return;

            var currentValues = state.IsDeleted
                ? state.ObjectStateEntry.OriginalValues
                : state.ObjectStateEntry.CurrentValues;

            foreach (var keyMember in keys)
            {
                var auditkey = new AuditKey();
                try
                {
                    var name = keyMember.Name;
                    auditkey.Name = name;
                    auditkey.Type = GetType(keyMember);

                    object value = currentValues.GetValue(name);
                    value = FormatValue(state, name, value);

                    auditkey.Value = value;
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.Message);
                    auditkey.Value = _errorText;
                }
                state.AuditEntity.Keys.Add(auditkey);
            }
        }