Пример #1
0
        /// <summary>
        /// Duplicates DbContentStatus object into a database; may or may not be the same database
        /// as the parent object.
        /// </summary>
        /// <returns> A new DbContentStatus object reflecting the replicated DbContentStatus object.</returns>
        public DbContentStatus Duplicate()
        {
            DbContentStatus clonedDbContentStatus = this.Clone();

            // Insert must be called after children are replicated!
            clonedDbContentStatus.iD       = DbContentStatusManager._insert(clonedDbContentStatus);
            clonedDbContentStatus.isSynced = true;
            return(clonedDbContentStatus);
        }
Пример #2
0
        /// <summary>
        /// Ensures that the object's fields and children are
        /// pre-loaded before any updates or reads.
        /// </summary>
        public void EnsurePreLoad()
        {
            if (!isPlaceHolder)
            {
                return;
            }

            DbContentStatusManager._fill(this);
            isPlaceHolder = false;
        }
Пример #3
0
        /// <summary>
        /// Saves the DbContentStatus object state to the database.
        /// </summary>
        public int Save()
        {
            if (isSynced)
            {
                return(iD);
            }

            if (iD == -1)
            {
                throw (new Exception("Invalid record; cannot be saved."));
            }
            if (iD == 0)
            {
                iD = DbContentStatusManager._insert(this);
            }
            else
            {
                DbContentStatusManager._update(this);
            }
            isSynced = iD != -1;
            return(iD);
        }
Пример #4
0
 /// <summary>
 /// Overwrites and existing DbContentStatus object in the database.
 /// </summary>
 public void Overwrite(int id)
 {
     iD = id;
     DbContentStatusManager._update(this);
     isSynced = true;
 }
Пример #5
0
 public void Delete()
 {
     DbContentStatusManager._delete(this.iD);
     this.iD  = 0;
     isSynced = false;
 }
Пример #6
0
 public DbContentStatus(int id)
 {
     this.iD  = id;
     isSynced = DbContentStatusManager._fill(this);
 }
Пример #7
0
        public DbContentHitCollection GetCollection(int topCount, string whereClause, string sortClause, params DbContentHitFlags[] optionFlags)
        {
            StringBuilder          query;
            Database               database;
            DbCommand              dbCommand;
            IDataReader            r;
            DbContentHitCollection dbContentHitCollection;

            int innerJoinOffset;

            query = new StringBuilder("SELECT ");

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

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

            innerJoinOffset = InnerJoinFields.GetUpperBound(0) + 1;
            int userOffset                        = -1;
            int userContactOffset                 = -1;
            int requestContentOffset              = -1;
            int requestContentStatusOffset        = -1;
            int requestContentParentCatalogOffset = -1;
            int requestContentRatingOffset        = -1;
            int requestContentWorkingDraftOffset  = -1;

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

                    case DbContentHitFlags.UserContact:
                        for (int i = 0; i <= GreyFoxContactManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("User_Contact.");
                            query.Append(GreyFoxContactManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        userContactOffset = innerJoinOffset;
                        innerJoinOffset   = userContactOffset + GreyFoxContactManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DbContentHitFlags.RequestContent:
                        for (int i = 0; i <= DbContentClipManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("RequestContent.");
                            query.Append(DbContentClipManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        requestContentOffset = innerJoinOffset;
                        innerJoinOffset      = requestContentOffset + DbContentClipManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DbContentHitFlags.RequestContentStatus:
                        for (int i = 0; i <= DbContentStatusManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("RequestContent_Status.");
                            query.Append(DbContentStatusManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        requestContentStatusOffset = innerJoinOffset;
                        innerJoinOffset            = requestContentStatusOffset + DbContentStatusManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DbContentHitFlags.RequestContentParentCatalog:
                        for (int i = 0; i <= DbContentCatalogManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("RequestContent_ParentCatalog.");
                            query.Append(DbContentCatalogManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        requestContentParentCatalogOffset = innerJoinOffset;
                        innerJoinOffset = requestContentParentCatalogOffset + DbContentCatalogManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DbContentHitFlags.RequestContentRating:
                        for (int i = 0; i <= DbContentRatingManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("RequestContent_Rating.");
                            query.Append(DbContentRatingManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        requestContentRatingOffset = innerJoinOffset;
                        innerJoinOffset            = requestContentRatingOffset + DbContentRatingManager.InnerJoinFields.GetUpperBound(0) + 1;
                        break;

                    case DbContentHitFlags.RequestContentWorkingDraft:
                        for (int i = 0; i <= DbContentClipManager.InnerJoinFields.GetUpperBound(0); i++)
                        {
                            query.Append("RequestContent_WorkingDraft.");
                            query.Append(DbContentClipManager.InnerJoinFields[i]);
                            query.Append(",");
                        }
                        requestContentWorkingDraftOffset = innerJoinOffset;
                        innerJoinOffset = requestContentWorkingDraftOffset + DbContentClipManager.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_Hits AS DbContentHit");
            }
            else
            {
                query.Append(" FROM kitCms_Hits AS DbContentHit");
            }
            //
            // Finish INNER JOIN expressions
            //
            if (optionFlags != null)
            {
                for (int x = 0; x < optionFlags.Length; x++)
                {
                    switch (optionFlags[x])
                    {
                    case DbContentHitFlags.User:
                        query.Append(" LEFT JOIN sysGlobal_Users AS User ON DbContentHit.UserID = User.GreyFoxUserID)");
                        break;

                    case DbContentHitFlags.UserContact:
                        query.Append(" LEFT JOIN sysGlobal_Contacts AS User_Contact ON User.ContactID = User_Contact.GreyFoxContactID)");
                        break;

                    case DbContentHitFlags.RequestContent:
                        query.Append(" LEFT JOIN kitCms_Clips AS RequestContent ON DbContentHit.RequestContentID = RequestContent.DbContentClipID)");
                        break;

                    case DbContentHitFlags.RequestContentStatus:
                        query.Append(" LEFT JOIN kitCms_Statuses AS RequestContent_Status ON RequestContent.StatusID = RequestContent_Status.DbContentStatusID)");
                        break;

                    case DbContentHitFlags.RequestContentParentCatalog:
                        query.Append(" LEFT JOIN kitCms_Catalogs AS RequestContent_ParentCatalog ON RequestContent.ParentCatalogID = RequestContent_ParentCatalog.DbContentCatalogID)");
                        break;

                    case DbContentHitFlags.RequestContentRating:
                        query.Append(" LEFT JOIN kitCms_Ratings AS RequestContent_Rating ON RequestContent.RatingID = RequestContent_Rating.DbContentRatingID)");
                        break;

                    case DbContentHitFlags.RequestContentWorkingDraft:
                        query.Append(" LEFT JOIN kitCms_Clips AS RequestContent_WorkingDraft ON RequestContent.WorkingDraftID = RequestContent_WorkingDraft.DbContentClipID)");
                        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

            dbContentHitCollection = new DbContentHitCollection();

            while (r.Read())
            {
                DbContentHit dbContentHit = ParseFromReader(r, 0, 1);

                // Fill User
                if (userOffset != -1 && !r.IsDBNull(userOffset))
                {
                    GreyFoxUserManager.FillFromReader(dbContentHit.user, r, userOffset, userOffset + 1);

                    // Fill
                    if (userContactOffset != -1 && !r.IsDBNull(userContactOffset))
                    {
                        GreyFoxContactManager.FillFromReader(dbContentHit.user.Contact, "sysGlobal_Contacts", r, userContactOffset, userContactOffset + 1);
                    }
                }

                // Fill RequestContent
                if (requestContentOffset != -1 && !r.IsDBNull(requestContentOffset))
                {
                    DbContentClipManager.FillFromReader(dbContentHit.requestContent, r, requestContentOffset, requestContentOffset + 1);

                    // Fill
                    if (requestContentStatusOffset != -1 && !r.IsDBNull(requestContentStatusOffset))
                    {
                        DbContentStatusManager.FillFromReader(dbContentHit.requestContent.Status, r, requestContentStatusOffset, requestContentStatusOffset + 1);
                    }

                    // Fill Parent Catalog
                    if (requestContentParentCatalogOffset != -1 && !r.IsDBNull(requestContentParentCatalogOffset))
                    {
                        DbContentCatalogManager.FillFromReader(dbContentHit.requestContent.ParentCatalog, r, requestContentParentCatalogOffset, requestContentParentCatalogOffset + 1);
                    }

                    // Fill
                    if (requestContentRatingOffset != -1 && !r.IsDBNull(requestContentRatingOffset))
                    {
                        DbContentRatingManager.FillFromReader(dbContentHit.requestContent.Rating, r, requestContentRatingOffset, requestContentRatingOffset + 1);
                    }

                    // Fill
                    if (requestContentWorkingDraftOffset != -1 && !r.IsDBNull(requestContentWorkingDraftOffset))
                    {
                        DbContentClipManager.FillFromReader(dbContentHit.requestContent.WorkingDraft, r, requestContentWorkingDraftOffset, requestContentWorkingDraftOffset + 1);
                    }
                }

                dbContentHitCollection.Add(dbContentHit);
            }

            return(dbContentHitCollection);
        }
Пример #8
0
 public void Delete()
 {
     DbContentStatusManager._delete(this.iD);
 }