public static AuditInfoEntity FetchAuditInfo(DataAccessAdapterBase adapter, PrefetchPath2 prefetchPath, long AuditInfoId) { AuditInfoEntity _AuditInfoEntity = new AuditInfoEntity(AuditInfoId); adapter.FetchEntity(_AuditInfoEntity, prefetchPath); return _AuditInfoEntity; }
/// <summary> /// Saves data from changed fields in JSON. /// Enables to track entity history. /// </summary> private void AuditInfo(IEntity2 entity, AuditInfoActionTypeEnum auditInfoActionTypeEnum) { AuditInfoEntity auditInfo = new AuditInfoEntity(); auditInfo.ActionDateTime = DateTime.Now; auditInfo.AuditInfoActionTypeId = (long)auditInfoActionTypeEnum; auditInfo.EntityId = (long)(EntityEnum)Enum.Parse(typeof(EntityEnum), entity.LLBLGenProEntityName.Replace("Entity", "")); auditInfo.UserId = this.UserId.Value; System.Collections.Generic.Dictionary<string, object> fieldsDictionary = new System.Collections.Generic.Dictionary<string, object>(); foreach (IEntityField2 field in entity.Fields) { string concurrencyFieldName = ConfigurationManager.AppSettings["ConcurrencyFieldName"]; // Saves all fields if is not update. // If it is update, saves only changed fileds. if (field.IsPrimaryKey) { // primary key is saved in separately auditInfo.PrimaryKeyValue = (long)field.CurrentValue; } else if (AuditInfoActionTypeEnum.Delete == auditInfoActionTypeEnum) { // nothing, you can recreate entity from other audit infos for this entity } else if ((auditInfoActionTypeEnum != AuditInfoActionTypeEnum.Update || field.IsChanged) && !field.IsPrimaryKey && field.Name != concurrencyFieldName) { fieldsDictionary.Add(field.Name, field.CurrentValue); } } auditInfo.JsonData = Newtonsoft.Json.JsonConvert.SerializeObject(fieldsDictionary); this.SaveEntity(auditInfo, false, false); }