private IEnumerable <AuditLogDetail> CreateComplexTypeLogDetails(string propertyName)
        {
            NavigationEntry entryMember = DbEntry.Member(propertyName) as NavigationEntry;

            if (entryMember != null)
            {
                Type complexTypeObj = entryMember.CurrentValue.GetType();

                foreach (PropertyInfo pi in complexTypeObj.GetProperties())
                {
                    string complexTypePropertyName = $"{propertyName}_{pi.Name}";
                    object complexTypeOrigValue    = OriginalValue(propertyName);
                    object complexTypeNewValue     = CurrentValue(propertyName);

                    object origValue = complexTypeOrigValue == null ? null : pi.GetValue(complexTypeOrigValue);
                    object newValue  = complexTypeNewValue == null ? null : pi.GetValue(complexTypeNewValue);

                    Comparator comparator = ComparatorFactory.GetComparator(complexTypeObj);

                    if (!comparator.AreEqual(newValue, origValue))
                    {
                        yield return(new AuditLogDetail
                        {
                            PropertyName = complexTypePropertyName,
                            OriginalValue = origValue?.ToString(),
                            NewValue = newValue?.ToString(),
                            Log = _log
                        });
                    }
                }
            }
        }
        protected virtual bool IsValueChanged(string propertyName)
        {
            var prop         = DbEntry.Property(propertyName);
            var propertyType = DbEntry.Entity.GetType().GetProperty(propertyName).PropertyType;

            object originalValue = OriginalValue(propertyName);
            object currentValue  = CurrentValue(propertyName);

            Comparator comparator = ComparatorFactory.GetComparator(propertyType);

            var changed = (StateOfEntity() == EntityState.Modified &&
                           prop.IsModified && !comparator.AreEqual(CurrentValue(propertyName), originalValue));

            if ((Type)propertyType == typeof(Byte[]) && changed)
            {
                if (!((IStructuralEquatable)originalValue).Equals(currentValue, StructuralComparisons.StructuralEqualityComparer))
                {
                    throw new Exception("EX_UltimaActualizacion");
                }
                else
                {
                    return(false);
                }
            }
            return(changed);
        }
        protected virtual bool IsValueChanged(string propertyName)
        {
            if (IsComplexType(propertyName))
            {
                var prop         = DbEntry.Reference(propertyName);
                var propertyType = DbEntry.Entity.GetType().GetProperty(propertyName).PropertyType;

                object originalValue = OriginalValue(propertyName);

                Comparator comparator = ComparatorFactory.GetComparator(propertyType);

                var changed = (StateOfEntity() == EntityState.Modified &&
                               prop.IsModified && !comparator.AreEqual(CurrentValue(propertyName), originalValue));
                return(changed);
            }
            else
            {
                var prop         = DbEntry.Property(propertyName);
                var propertyType = DbEntry.Entity.GetType().GetProperty(propertyName).PropertyType;

                object originalValue = OriginalValue(propertyName);

                Comparator comparator = ComparatorFactory.GetComparator(propertyType);

                var changed = (StateOfEntity() == EntityState.Modified &&
                               prop.IsModified && !comparator.AreEqual(CurrentValue(propertyName), originalValue));
                return(changed);
            }
        }
Ejemplo n.º 4
0
        protected override bool IsValueChanged(string propertyName)
        {
            var prop         = DbEntry.Property(propertyName);
            var propertyType = DbEntry.Entity.GetType().GetProperty(propertyName).PropertyType;

            object originalValue = OriginalValue(propertyName);

            Comparator comparator = ComparatorFactory.GetComparator(propertyType);

            var changed = prop.IsModified && !comparator.AreEqual(CurrentValue(propertyName), originalValue);

            return(changed);
        }
        protected override bool IsValueChanged(string propertyName)
        {
            if (GlobalTrackingConfig.TrackEmptyPropertiesOnAdditionAndDeletion)
            {
                return(true);
            }

            var    propertyType = DbEntry.Entity.GetType().GetProperty(propertyName).PropertyType;
            object defaultValue = propertyType.DefaultValue();
            object currentValue = CurrentValue(propertyName);

            Comparator comparator = ComparatorFactory.GetComparator(propertyType);

            return(!comparator.AreEqual(defaultValue, currentValue));
        }