private void AddDataStoreItemAlterations(IDataStoreItem item) { foreach (PropertyInfo p in item.ConcreteType.GetProperties()) { System.Diagnostics.Debug.WriteLine("p.Name = " + p.Name); Attribute[] attrs = Attribute.GetCustomAttributes(p); foreach (System.Attribute attr in attrs) { System.Diagnostics.Debug.WriteLine("attr.ToString() = " + attr.ToString()); if (attr is AuditableAttribute) { Type t = p.PropertyType; var oldVal = db.Entry(item).OriginalValues.GetValue <object>(p.Name); PropertyInfo pi = item.GetType().GetProperty(p.Name); if (oldVal == null) { System.Diagnostics.Debug.WriteLine("oldVal IS null"); DataStoreItemAlteration d = new DataStoreItemAlteration(); d.ItemIDNumber = item.ID; d.Workstation = Platform.CurrentWorkstation; d.PropertyName = p.Name; d.OldValue = ""; if (pi.GetValue(item, null) == null) { d.NewValue = ""; } else { d.NewValue = pi.GetValue(item, null).ToString(); d.DataStoreItemName = item.ConcreteType.Name; db.DataStoreItemAlterations.Add(d); } } else if (pi.GetValue(item, null).ToString() != oldVal.ToString()) { System.Diagnostics.Debug.WriteLine("oldVal is Not null"); DataStoreItemAlteration d = new DataStoreItemAlteration(); d.ItemIDNumber = item.ID; d.Workstation = Platform.CurrentWorkstation; d.PropertyName = p.Name; d.OldValue = oldVal.ToString(); d.NewValue = pi.GetValue(item, null).ToString(); d.DataStoreItemName = item.ConcreteType.Name; db.DataStoreItemAlterations.Add(d); } } } } }
private void AddDataStoreItemAlterations(IDataStoreItem item) { foreach (PropertyInfo p in item.ConcreteType.GetProperties()) { if (p.Name == "LastEditDate") { continue; } if (!p.CanWrite) { continue; } if (p.PropertyType.IsPrimitive || p.PropertyType == typeof(string) || p.PropertyType == typeof(DateTime)) { Type t = p.PropertyType; var oldVal = db.Entry(item).OriginalValues.GetValue <object>(p.Name); PropertyInfo pi = item.GetType().GetProperty(p.Name); if (oldVal == null) { DataStoreItemAlteration d = new DataStoreItemAlteration(); d.ItemIDNumber = item.ID; d.Workstation = null; d.PropertyName = p.Name; d.OldValue = ""; if (pi.GetValue(item, null) == null) { d.NewValue = ""; } else { d.NewValue = pi.GetValue(item, null).ToString(); } d.DataStoreItemName = item.ConcreteType.Name; db.DataStoreItemAlterations.Add(d); } else if (pi.GetValue(item, null).ToString() != oldVal.ToString()) { DataStoreItemAlteration d = new DataStoreItemAlteration(); d.Workstation = null; d.PropertyName = p.Name; d.OldValue = oldVal.ToString(); d.NewValue = pi.GetValue(item, null).ToString(); d.DataStoreItemName = item.ConcreteType.Name; db.DataStoreItemAlterations.Add(d); } } } }