Esempio n. 1
0
        /// <summary>
        /// Makes a shallow copy of the current DbContentRatingCollection.
        /// as the parent object.
        /// </summary>
        /// <returns>DbContentRatingCollection</returns>
        public DbContentRatingCollection Clone()
        {
            DbContentRatingCollection clonedDbContentRating = new DbContentRatingCollection(count);

            lock (this)
            {
                foreach (DbContentRating item in this)
                {
                    clonedDbContentRating.Add(item);
                }
            }
            return(clonedDbContentRating);
        }
Esempio n. 2
0
        /// <summary>
        /// Makes a deep copy of the current DbContentRating.
        /// </summary>
        /// <param name="isolation">Placeholders are used to isolate the
        /// items in the DbContentRatingCollection from their children.</param>
        public DbContentRatingCollection Copy(bool isolated)
        {
            DbContentRatingCollection isolatedCollection = new DbContentRatingCollection(count);

            lock (this)
            {
                if (isolated)
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(DbContentRatingArray[i].NewPlaceHolder());
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        isolatedCollection.Add(DbContentRatingArray[i].Copy());
                    }
                }
            }
            return(isolatedCollection);
        }
Esempio n. 3
0
        public DbContentRatingCollection GetCollection(int topCount, string whereClause, string sortClause, params DbContentRatingFlags[] optionFlags)
        {
            StringBuilder             query;
            Database                  database;
            DbCommand                 dbCommand;
            IDataReader               r;
            DbContentRatingCollection dbContentRatingCollection;

            int innerJoinOffset;

            query = new StringBuilder("SELECT ");

            if (topCount > 0)
            {
                query.Append("TOP ");
                query.Append(topCount);
                query.Append(" ");
            }

            foreach (string columnName in InnerJoinFields)
            {
                query.Append("DbContentRating.");
                query.Append(columnName);
                query.Append(",");
            }

            innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1;
            int requiredRoleOffset = -1;

            //
            // Append Option Flag Fields
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DbContentRatingFlags.RequiredRole:
                        for (int i = 0; i <= GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("RequiredRole.");
                            query.Append(GreyFoxRoleManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        requiredRoleOffset = innerJoinOffset;
                        innerJoinOffset    = requiredRoleOffset + GreyFoxRoleManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;
                    }
                }
            }

            //
            // Remove trailing comma
            //
            query.Length--;
            if (optionFlags != null)
            {
                query.Append(" FROM ");

                //
                // Start INNER JOIN expressions
                //
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    query.Append("(");
                }

                query.Append("kitCms_Ratings AS DbContentRating");
            }
            else
            {
                query.Append(" FROM kitCms_Ratings AS DbContentRating");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DbContentRatingFlags.RequiredRole:
                        query.Append(" LEFT JOIN sysGlobal_Roles AS RequiredRole ON DbContentRating.RequiredRoleID = RequiredRole.GreyFoxRoleID)");
                        break;
                    }
                }
            }

            //
            // Render where clause
            //
            if (whereClause != string.Empty)
            {
                query.Append(" WHERE ");
                query.Append(whereClause);
            }

            //
            // Render sort clause
            //
            if (sortClause != string.Empty)
            {
                query.Append(" ORDER BY ");
                query.Append(sortClause);
            }

            //
            // Render final semicolon
            //
            query.Append(";");
            database  = DatabaseFactory.CreateDatabase();
            dbCommand = database.GetSqlStringCommand(query.ToString());
                        #if DEBUG
            try
            {
                r = database.ExecuteReader(dbCommand);
            }
            catch (Exception e)
            {
                string msg = e.Message;
                throw(new Exception(msg + " --- Query: " + query.ToString()));
            }
                        #else
            r = database.ExecuteReader(dbCommand);
                        #endif

            dbContentRatingCollection = new DbContentRatingCollection();

            while (r.Read())
            {
                DbContentRating dbContentRating = ParseFromReader(r, 0, 1);

                // Fill RequiredRole
                if (requiredRoleOffset != -1 && !r.IsDBNull(requiredRoleOffset))
                {
                    GreyFoxRoleManager.FillFromReader(dbContentRating.requiredRole, r, requiredRoleOffset, requiredRoleOffset + 1);
                }

                dbContentRatingCollection.Add(dbContentRating);
            }

            return(dbContentRatingCollection);
        }