예제 #1
0
        public static void UpdateFeaturedChannels()
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbcommand = db.GetSqlStringCommand("select top 10 * from Channel");
            IDataReader dr = db.ExecuteReader(dbcommand);

            List<Channel> VideosByFeature = PopulateObject(dr);

            db = DatabaseFactory.CreateDatabase();

            DbConnection dbConn = db.CreateConnection();
            dbConn.Open();

            DbTransaction transaction = dbConn.BeginTransaction();

            DbCommand dbcommandDelete = db.GetSqlStringCommand("DELETE FROM FeaturedChannel");
            db.ExecuteNonQuery(dbcommandDelete);

            for (int i = 0; i < VideosByFeature.Count; i++)
            {
                FeaturedChannel FeaturedChan = new FeaturedChannel();
                FeaturedChan.Position = (i + 1);
                FeaturedChan.ChannelID = VideosByFeature[i].ChannelID;
                FeaturedChan.Save() ;
            }

            transaction.Commit();
        }
예제 #2
0
        /// <summary>
        /// Takes an prepopulated IDataReader and creates an array of FeaturedChannels
        /// </summary>
        public static List<FeaturedChannel> PopulateObject(IDataReader dr)
        {
            ColumnFieldList list = new ColumnFieldList(dr);

            List<FeaturedChannel> arr = new List<FeaturedChannel>();

            FeaturedChannel obj;

            while (dr.Read())
            {
                obj = new FeaturedChannel();
                if (list.IsColumnPresent("FeaturedChannelID")) { obj._featuredChannelID = (int)dr["FeaturedChannelID"]; }
                if (list.IsColumnPresent("Position")) { obj._position = (int)dr["Position"]; }
                if (list.IsColumnPresent("ChannelID")) { obj._channelID = (int)dr["ChannelID"]; }

                arr.Add(obj);
            }

            dr.Close();

            return arr;
        }