public static void SetDataKeyValue(string dataKeyName, string dataKeyValue)
        {
            string _connStr = SetConn();

            SQLUpdateNugget n = SQLUpdateNugget.GetNuggets("SchemaVersionUpdate").FirstOrDefault();

            if (n != null)
            {
                List <SqlParameter> parms = new List <SqlParameter>();

                SqlParameter parmNewVal = new SqlParameter();
                parmNewVal.ParameterName = "@DataValue";
                parmNewVal.SqlDbType     = SqlDbType.VarChar;
                parmNewVal.Size          = 100;
                parmNewVal.Direction     = ParameterDirection.Input;
                parmNewVal.Value         = dataKeyValue;

                parms.Add(parmNewVal);

                SqlParameter parmKey = new SqlParameter();
                parmKey.ParameterName = "@DataKey";
                parmKey.SqlDbType     = SqlDbType.VarChar;
                parmKey.Size          = 100;
                parmKey.Direction     = ParameterDirection.Input;
                parmKey.Value         = dataKeyName;

                parms.Add(parmKey);

                ExecuteNonQueryCommands(_connStr, n.SQLQuery, parms);
            }
        }
        public DatabaseUpdateResponse AlterStep13()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            bool bTestResult = SQLUpdateNugget.EvalNuggetKey("AlterStep13");

            if (bTestResult)
            {
                res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.ALTER13.sql", false);
                res.Response      = "Update timezone sproc";
                res.RanUpdate     = true;
                SetDbSchemaVersion(DatabaseUpdate.DbVersion13);
                return(res);
            }
            else
            {
                // if the db version is off, check leading tidbit against current and immediate prior
                DataInfo ver = GetDbSchemaVersion();

                if (DatabaseUpdate.DbVersion12.Substring(0, 6) == ver.DataValue.Substring(0, 6))
                {
                    SetDbSchemaVersion(DatabaseUpdate.DbVersion13);
                }
            }

            res.Response = "Timezone sproc update already applied";
            return(res);
        }
        public bool DatabaseNeedsUpdate()
        {
            if (!DatabaseUpdate.FailedSQL)
            {
                bool bTestResult = false;

                DataInfo ver = GetDbSchemaVersion();
                bTestResult = ver.DataValue != DatabaseUpdate.CurrentDbVersion;
                if (bTestResult)
                {
                    return(true);
                }

                bTestResult = SQLUpdateNugget.EvalNuggetKey("DatabaseNeedsUpdate");
                if (bTestResult)
                {
                    return(true);
                }

                bTestResult = SQLUpdateNugget.EvalNuggetKey("PreCarrotPrefix");
                if (bTestResult)
                {
                    return(true);
                }

                bTestResult = SQLUpdateNugget.EvalManditoryChecks();
                if (bTestResult)
                {
                    return(true);
                }
            }

            return(false);
        }
        public DatabaseUpdateResponse CreateCMSDatabase()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            if (!DatabaseUpdate.FailedSQL)
            {
                bool bTestResult = SQLUpdateNugget.EvalNuggetKey("DoCMSTablesExist");

                if (!bTestResult)
                {
                    res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.CREATE01.sql", false);
                    res.Response      = "Created Database";
                    res.RanUpdate     = true;
                    // change version key when the DB creation is rescripted
                    SetDbSchemaVersion(DatabaseUpdate.DbVersion12);
                    return(res);
                }

                res.Response = "Database Already Created";
                return(res);
            }

            res.Response = "*** Database Access Failed ***";
            return(res);
        }
        public DatabaseUpdateResponse AlterStep01()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            bool bTestResult = SQLUpdateNugget.EvalNuggetKey("AlterStep01");

            if (bTestResult)
            {
                res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.ALTER01.sql", false);
                res.Response      = "Update comment view";
                res.RanUpdate     = true;
                SetDbSchemaVersion(DatabaseUpdate.DbVersion01);
                return(res);
            }
            else
            {
                // if the db version is off, check leading tidbit against current and immediate prior
                DataInfo ver = GetDbSchemaVersion();
                if (DatabaseUpdate.DbVersion00.Substring(0, 6) == ver.DataValue.Substring(0, 6) ||
                    "201510" == ver.DataValue.Substring(0, 6) || "201509" == ver.DataValue.Substring(0, 6) || "201508" == ver.DataValue.Substring(0, 6) ||
                    DatabaseUpdate.DbVersion01.Substring(0, 6) == ver.DataValue.Substring(0, 6))
                {
                    SetDbSchemaVersion(DatabaseUpdate.DbVersion01);
                }
            }

            res.Response = "Comment view update already applied";
            return(res);
        }
        public static bool AreCMSTablesIncomplete()
        {
            if (!DatabaseUpdate.FailedSQL)
            {
                bool bTestResult = false;

                DataInfo ver = GetDbSchemaVersion();
                bTestResult = ver.DataValue != DatabaseUpdate.CurrentDbVersion;
                if (bTestResult)
                {
                    return(true);
                }

                bTestResult = SQLUpdateNugget.EvalNuggetKey("AreCMSTablesIncomplete");
                if (bTestResult)
                {
                    return(true);
                }

                bTestResult = SQLUpdateNugget.EvalManditoryChecks();
                if (bTestResult)
                {
                    return(true);
                }
            }

            return(false);
        }
        public bool DoCMSTablesExist()
        {
            if (!DatabaseUpdate.FailedSQL)
            {
                bool bTestResult = SQLUpdateNugget.EvalNuggetKey("DoCMSTablesExist");

                if (bTestResult)
                {
                    return(bTestResult);
                }
            }

            return(false);
        }
        public DatabaseUpdateResponse AlterStep09()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            bool bTestResult = SQLUpdateNugget.EvalNuggetKey("AlterStep09");

            if (bTestResult)
            {
                res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.ALTER09.sql", false);
                res.Response      = "CMS DB created vw_carrot_ContentChild and ShowInSiteNav";
                res.RanUpdate     = true;
                return(res);
            }

            res.Response = "CMS DB vw_carrot_ContentChild and ShowInSiteNav already exist";
            return(res);
        }
        public DatabaseUpdateResponse AlterStep07()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            bool bTestResult = SQLUpdateNugget.EvalNuggetKey("AlterStep07");

            if (bTestResult)
            {
                res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.ALTER07.sql", false);
                res.Response      = "CMS DB created cols RetireDate, GoLiveDate, and GoLiveDateLocal in carrot_RootContent";
                res.RanUpdate     = true;
                return(res);
            }

            res.Response = "CMS DB cols RetireDate, GoLiveDate, and GoLiveDateLocal in carrot_RootContent already exist";
            return(res);
        }
        public DatabaseUpdateResponse AlterStep06()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            bool bTestResult = SQLUpdateNugget.EvalNuggetKey("AlterStep06");

            if (bTestResult)
            {
                res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.ALTER06.sql", false);
                res.Response      = "CMS DB created carrot_ContentType, carrot_ContentTag, carrot_ContentCategory";
                res.RanUpdate     = true;
                return(res);
            }

            res.Response = "CMS DB carrot_ContentType, carrot_ContentTag, carrot_ContentCategory already exist";
            return(res);
        }
        public DatabaseUpdateResponse AlterStep04()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            bool bTestResult = SQLUpdateNugget.EvalNuggetKey("AlterStep04");

            if (bTestResult)
            {
                res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.ALTER04.sql", false);
                res.Response      = "CMS Table Names Changed";
                res.RanUpdate     = true;
                return(res);
            }

            res.Response = "CMS Tables Already Changed";
            return(res);
        }
        public DatabaseUpdateResponse AlterStep03()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            bool bTestResult = SQLUpdateNugget.EvalNuggetKey("AlterStep03");

            if (bTestResult)
            {
                res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.ALTER03.sql", false);
                res.Response      = "RootContent CreateDate Created";
                res.RanUpdate     = true;
                return(res);
            }

            res.Response = "RootContent CreateDate Already Exists";
            return(res);
        }
        public DatabaseUpdateResponse AlterStep01()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            bool bTestResult = SQLUpdateNugget.EvalNuggetKey("AlterStep01");

            if (bTestResult)
            {
                res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.ALTER01.sql", false);
                res.Response      = "Created Content MetaKeyword and MetaDescription";
                res.RanUpdate     = true;
                return(res);
            }

            res.Response = "Content MetaKeyword and MetaDescription Already Exists";
            return(res);
        }
        public DatabaseUpdateResponse AlterStep12()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            bool bTestResult = SQLUpdateNugget.EvalNuggetKey("AlterStep12");

            if (bTestResult)
            {
                res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.ALTER12.sql", false);
                res.Response      = "CMS DB Updated time zone sproc and tallies";
                res.RanUpdate     = true;
                SetDbSchemaVersion(DatabaseUpdate.DbVersion12);
                return(res);
            }

            res.Response = "CMS DB time zone sproc already updated";
            return(res);
        }
        public DatabaseUpdateResponse AlterStep10()
        {
            DatabaseUpdateResponse res = new DatabaseUpdateResponse();

            bool bTestResult = SQLUpdateNugget.EvalNuggetKey("AlterStep10");

            if (bTestResult)
            {
                res.LastException = ExecFileContents("Carrotware.CMS.DBUpdater.DataScripts.ALTER10.sql", false);
                res.Response      = "CMS DB created TextWidget and Content Snippet, updated edit history";
                res.RanUpdate     = true;
                SetDbSchemaVersion(DatabaseUpdate.DbVersion10);
                return(res);
            }

            res.Response = "CMS DB TextWidget and Content Snippet already exist";
            return(res);
        }
        public static DataInfo GetDataKeyValue(string dataKeyName)
        {
            string _connStr = SetConn();

            DataInfo d = new DataInfo();

            SQLUpdateNugget n = SQLUpdateNugget.GetNuggets("SchemaVersionCheck").FirstOrDefault();

            if (n != null)
            {
                List <SqlParameter> parms = new List <SqlParameter>();

                SqlParameter parmKey = new SqlParameter();
                parmKey.ParameterName = "@DataKey";
                parmKey.SqlDbType     = SqlDbType.VarChar;
                parmKey.Size          = 100;
                parmKey.Direction     = ParameterDirection.Input;
                parmKey.Value         = dataKeyName;

                parms.Add(parmKey);

                DataTable dt = ExecuteDataTableCommands(_connStr, n.SQLQuery, parms);

                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];

                    d.DataKey   = dr["DataKey"].ToString();
                    d.DataValue = dr["DataValue"].ToString();
                }
            }

            if (d != null && string.IsNullOrEmpty(d.DataValue))
            {
                d.DataValue = String.Empty;
            }

            return(d);
        }