Esempio n. 1
0
        public override Hashtable GetImressionsTypesForUsers(int[] userIDs, int top)
        {
            using (SqlQuery db = new SqlQuery())
            {
                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < userIDs.Length; i++)
                {
                    sb.Append("SELECT TOP (@Top) A.*, B.UserID FROM bx_ImpressionTypes A RIGHT JOIN bx_Impressions B ON A.TypeID = B.TypeID WHERE B.UserID = ").Append(userIDs[i]).AppendLine("");

                    if (i < userIDs.Length - 1)
                    {
                        sb.AppendLine("UNION");
                    }
                }

                sb.Append(" ORDER BY B.UserID");

                db.CommandText = sb.ToString();

                db.CreateTopParameter("@Top", top);

                using (XSqlDataReader reader = db.ExecuteReader())
                {
                    Hashtable result = new Hashtable();

                    ImpressionTypeCollection types = null;

                    int lastUserId = -1;

                    while (reader.Read())
                    {
                        int userID = reader.Get <int>("UserID");

                        ImpressionType type = new ImpressionType(reader);

                        if (userID != lastUserId)
                        {
                            lastUserId = userID;

                            types = new ImpressionTypeCollection();

                            result.Add(userID, types);
                        }

                        types.Add(type);
                    }

                    return(result);
                }
            }
        }
Esempio n. 2
0
        public override Hashtable GetImressionsTypesForUsers(int[] userIDs, int top)
        {
            using (SqlQuery db = new SqlQuery())
            {
                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < userIDs.Length; i++)
                {
                    sb.Append("SELECT TOP (@Top) A.*, B.UserID FROM bx_ImpressionTypes A RIGHT JOIN bx_Impressions B ON A.TypeID = B.TypeID WHERE B.UserID = ").Append(userIDs[i]).AppendLine("");

                    if (i < userIDs.Length - 1)
                        sb.AppendLine("UNION");
                }

                sb.Append(" ORDER BY B.UserID");

                db.CommandText = sb.ToString();

                db.CreateTopParameter("@Top", top);

                using (XSqlDataReader reader = db.ExecuteReader())
                {
                    Hashtable result = new Hashtable();

                    ImpressionTypeCollection types = null;

                    int lastUserId = -1;

                    while (reader.Read())
                    {
                        int userID = reader.Get<int>("UserID");

                        ImpressionType type = new ImpressionType(reader);

                        if (userID != lastUserId)
                        {
                            lastUserId = userID;

                            types = new ImpressionTypeCollection();

                            result.Add(userID, types);
                        }

                        types.Add(type);
                    }

                    return result;
                }
            }
        }