public override IList<TransacDto> GetUserHistory(IUserContext userContext, long userId, IList<Type> entityTypes)
 {
     IList<long> entityIds = new List<long>();
     EntitiesModel context = userContext.Context as EntitiesModel;
     IQueryable<AuditTransac> query = context.GetAll<AuditTransac>().Where(p => p.UserId == userId).OrderByDescending(p => p.TransacId);
     if (entityTypes.Count > 0)
     {
         foreach (Type type in entityTypes)
         {
             if (!this.metaEntities.ContainsKey(type))
             {
                 throw new ArgumentException("Type not registered in meta: " + type.Name);
             }
             entityIds.Add(this.metaEntities[type].EntId);
         }
         query = query.Where(p => p.AuditTransacActions.Any(a => entityIds.Contains(a.EntId)));
     }
     IList<AuditTransac> allTransacEntities = query.ToList();
     IList<TransacDto> result = new List<TransacDto>();
     IList<WebUser> users = context.GetAll<WebUser>().ToList();
     Dictionary<int, WebUser> userMap = new Dictionary<int, WebUser>();
     foreach (WebUser user in users)
     {
         userMap.Add(user.UserId, user);
     }
     foreach (AuditTransac transacEntity in allTransacEntities)
     {
         TransacDto transac = new TransacDto();
         transac.Id = transacEntity.TransacId;
         transac.UserId = transacEntity.UserId;
         transac.UserName = userMap[transacEntity.UserId].Name;
         transac.StartDateTime = transacEntity.StartDttm;
         transac.EndDateTime = transacEntity.EndDttm.Value;
         result.Add(transac);
         IQueryable<AuditTransacAction> queryActions = context.GetAll<AuditTransacAction>().Where(p => p.TransacId == transac.Id).OrderBy(p => p.TransacActionIx);
         if (entityIds.Count > 0)
         {
             queryActions = queryActions.Where(a => entityIds.Contains(a.EntId));
         }
         IList<AuditTransacAction> actions = queryActions.ToList();
         foreach (AuditTransacAction actionEntity in actions)
         {
             TransacActionDto action = new TransacActionDto();
             action.TransacId = transac.Id;
             action.ActionIx = actionEntity.TransacActionIx;
             action.EntId = actionEntity.EntId;
             action.Operation = CharToAuditOperationType(actionEntity.ActionType);
             action.Change = actionEntity.ObjJson;
             if (this.metaEntitiesByKey.ContainsKey(actionEntity.EntId))
             {
                 MetaEntity meta = this.metaEntitiesByKey[actionEntity.EntId];
                 action.EntityName = meta.EntityName;
             }
             transac.Actions.Add(action);
         }
     }
     return result;
 }
 public override IList<TransacDto> GetTransactions(IUserContext userContext, AuditQueryInfo info)
 {
     IList<AuditTransac> allTransacEntities = this.GetEntityTransactions(userContext, info);
     IDictionary<long, UserDto> userMap = this.GetUserMap(userContext, info);
     IList<TransacDto> result = new List<TransacDto>();
     Dictionary<long, TransacDto> transacMap = new Dictionary<long, TransacDto>();
     foreach (AuditTransac transacEntity in allTransacEntities)
     {
         TransacDto transac = new TransacDto();
         transac.Id = transacEntity.TransacId;
         transac.UserId = transacEntity.UserId;
         transac.UserName = userMap[transacEntity.UserId].Name;
         transac.StartDateTime = transacEntity.StartDttm;
         transac.EndDateTime = transacEntity.EndDttm.Value;
         result.Add(transac);
         transacMap.Add(transac.Id, transac);
     }
     IList<AuditTransacAction> allTransacActionEntities = this.GetEntityTransacActions(userContext, info);
     foreach (AuditTransacAction actionEntity in allTransacActionEntities)
     {
         if (transacMap.ContainsKey(actionEntity.TransacId))
         {
             MetaEntity meta = this.metaEntitiesByKey[actionEntity.EntId];
             TransacDto transac = transacMap[actionEntity.TransacId];
             TransacActionDto action = new TransacActionDto();
             action.TransacId = transac.Id;
             action.ActionIx = actionEntity.TransacActionIx;
             action.EntId = actionEntity.EntId;
             action.Operation = CharToAuditOperationType(actionEntity.ActionType);
             action.Change = actionEntity.ObjJson;
             action.EntityName = meta.EntityName;
             transac.Actions.Add(action);
         }
     }
     return result;
 }