Exemplo n.º 1
0
		public GXActionResponse Post(GXActionRequest request)
		{
            lock (Db)
            {
                IAuthSession s = this.GetSession(false);
                List<string> Filter = new List<string>();
                string query = "SELECT * FROM " + GuruxAMI.Server.AppHost.GetTableName<GXAmiUserActionLog>(Db);
                if (request.DeviceIDs != null && request.DeviceIDs.Length != 0)
                {
                    string str = " TargetID IN(";
                    bool first = true;
                    foreach (ulong it in request.DeviceIDs)
                    {
                        if (!first)
                        {
                            str += ", ";
                        }
                        str += it.ToString();
                        first = false;
                    }
                    Filter.Add(str + ")");
                }
                if (request.DeviceGroupIDs != null && request.DeviceGroupIDs.Length != 0)
                {
                    string str = " TargetID IN(";
                    bool first = true;
                    foreach (ulong it in request.DeviceGroupIDs)
                    {
                        if (!first)
                        {
                            str += ", ";
                        }
                        str += it.ToString();
                        first = false;
                    }
                    Filter.Add(str + ")");
                }
                if (request.UserIDs != null && request.UserIDs.Length != 0)
                {
                    string str = " UserID IN(";
                    bool first = true;
                    foreach (ulong it in request.UserIDs)
                    {
                        if (!first)
                        {
                            str += ", ";
                        }
                        str += it.ToString();
                        first = false;
                    }
                    Filter.Add(str + ")");
                }
                if (request.UserGroupIDs != null && request.UserGroupIDs.Length != 0)
                {
                    string query2 = string.Format("SELECT DISTINCT {0}.ID FROM {0} INNER JOIN {1} ON {0}.ID = {1}.UserID WHERE UserGroupID IN (",
                        GuruxAMI.Server.AppHost.GetTableName<GXAmiUser>(Db),
                        GuruxAMI.Server.AppHost.GetTableName<GXAmiUserGroupUser>(Db));
                    bool first = true;
                    foreach (ulong it in request.UserGroupIDs)
                    {
                        if (!first)
                        {
                            query2 += ", ";
                        }
                        query2 += it.ToString();
                        first = false;
                    }
                    string str = " UserID IN(";
                    first = true;
                    List<long> userIDs = Db.Select<long>(query2);
                    foreach (long it in userIDs)
                    {
                        if (!first)
                        {
                            str += ", ";
                        }
                        str += it.ToString();
                        first = false;
                    }
                    Filter.Add(str + ")");

                }
                if (Filter.Count != 0)
                {
                    query += "WHERE ";
                    query += string.Join(" AND ", Filter.ToArray());
                }
                if (request.Descending)
                {
                    query += string.Format(" ORDER BY {0}.ID DESC ",                
                             GuruxAMI.Server.AppHost.GetTableName<GXAmiUserActionLog>(Db));
                }
                List<GXAmiUserActionLog> actions = Db.Select<GXAmiUserActionLog>(query);
                //Get actions by range.
                if (request.Index != 0 || request.Count != 0)
                {
                    if (request.Count == 0 || request.Index + request.Count > actions.Count)
                    {
                        request.Count = actions.Count - request.Index;
                    }
                    actions.RemoveRange(0, request.Index);
                    var limitUsers = actions.Take(request.Count);
                    actions = limitUsers.ToList();
                }
                return new GXActionResponse(actions.ToArray());
            }
		}
Exemplo n.º 2
0
 public GXActionResponse Post(GXActionRequest request)
 {
     lock (Db)
     {
         IAuthSession  s      = this.GetSession(false);
         List <string> Filter = new List <string>();
         string        query  = "SELECT * FROM " + GuruxAMI.Server.AppHost.GetTableName <GXAmiUserActionLog>(Db);
         if (request.DeviceIDs != null && request.DeviceIDs.Length != 0)
         {
             string str   = " TargetID IN(";
             bool   first = true;
             foreach (ulong it in request.DeviceIDs)
             {
                 if (!first)
                 {
                     str += ", ";
                 }
                 str  += it.ToString();
                 first = false;
             }
             Filter.Add(str + ")");
         }
         if (request.DeviceGroupIDs != null && request.DeviceGroupIDs.Length != 0)
         {
             string str   = " TargetID IN(";
             bool   first = true;
             foreach (ulong it in request.DeviceGroupIDs)
             {
                 if (!first)
                 {
                     str += ", ";
                 }
                 str  += it.ToString();
                 first = false;
             }
             Filter.Add(str + ")");
         }
         if (request.UserIDs != null && request.UserIDs.Length != 0)
         {
             string str   = " UserID IN(";
             bool   first = true;
             foreach (ulong it in request.UserIDs)
             {
                 if (!first)
                 {
                     str += ", ";
                 }
                 str  += it.ToString();
                 first = false;
             }
             Filter.Add(str + ")");
         }
         if (request.UserGroupIDs != null && request.UserGroupIDs.Length != 0)
         {
             string query2 = string.Format("SELECT DISTINCT {0}.ID FROM {0} INNER JOIN {1} ON {0}.ID = {1}.UserID WHERE UserGroupID IN (",
                                           GuruxAMI.Server.AppHost.GetTableName <GXAmiUser>(Db),
                                           GuruxAMI.Server.AppHost.GetTableName <GXAmiUserGroupUser>(Db));
             bool first = true;
             foreach (ulong it in request.UserGroupIDs)
             {
                 if (!first)
                 {
                     query2 += ", ";
                 }
                 query2 += it.ToString();
                 first   = false;
             }
             string str = " UserID IN(";
             first = true;
             List <long> userIDs = Db.Select <long>(query2);
             foreach (long it in userIDs)
             {
                 if (!first)
                 {
                     str += ", ";
                 }
                 str  += it.ToString();
                 first = false;
             }
             Filter.Add(str + ")");
         }
         if (Filter.Count != 0)
         {
             query += "WHERE ";
             query += string.Join(" AND ", Filter.ToArray());
         }
         if (request.Descending)
         {
             query += string.Format(" ORDER BY {0}.ID DESC ",
                                    GuruxAMI.Server.AppHost.GetTableName <GXAmiUserActionLog>(Db));
         }
         List <GXAmiUserActionLog> actions = Db.Select <GXAmiUserActionLog>(query);
         //Get actions by range.
         if (request.Index != 0 || request.Count != 0)
         {
             if (request.Count == 0 || request.Index + request.Count > actions.Count)
             {
                 request.Count = actions.Count - request.Index;
             }
             actions.RemoveRange(0, request.Index);
             var limitUsers = actions.Take(request.Count);
             actions = limitUsers.ToList();
         }
         return(new GXActionResponse(actions.ToArray()));
     }
 }