예제 #1
0
        public ActionResult AccessAnalytics(VMConfigAccessAnalytics args)
        {
            if (!this.ModelState.IsValid)
            {
                return new HttpNotFoundResult();
            }

            BlogConfig config = new BlogConfig();
            config.Name = "google_analytics";
            config.Value = args.GoogleAnalytics;
            List<BlogConfig> configs = new List<BlogConfig> { };
            configs.Add(config);
            bool result = HNKBlogConfigFetcher.UpdateConfigs(AppSettings.GetDbConnectionString(), configs);
            if (!result)
            {
                return new HttpStatusCodeResult(500);
            }

            VMConfigBase model = new VMConfigBase();
            return View("Index", model);
        }
예제 #2
0
        /// <summary>
        /// ブログの設定をすべて取得します
        /// </summary>
        public List<BlogConfig> GetBlogConfigs()
        {
            StringBuilder query = new StringBuilder();
            query.Append("SELECT id, name, value FROM blog_config");

            List<BlogConfig> configs = new List<BlogConfig> { };
            using (SqlCommand cmd = new SqlCommand(query.ToString(), this.SqlConnection))
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        BlogConfig config = new BlogConfig();
                        if (!reader.IsDBNull(0))
                        {
                            config.Id = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            config.Name = reader.GetString(1).Trim();
                        }

                        if (!reader.IsDBNull(2))
                        {
                            config.Value = reader.GetString(2).Trim();
                        }

                        if (config.Id > 0)
                        {
                            configs.Add(config);
                        }
                    }
                }
            }

            return configs;
        }
예제 #3
0
        /// <summary>
        /// 特定のブログの設定を取得します
        /// </summary>
        private BlogConfig GetBlogConfig(string name)
        {
            StringBuilder query = new StringBuilder();
            query.Append("SELECT id, name, value FROM blog_config WHERE name = @name");

            BlogConfig config = new BlogConfig();
            using (SqlCommand cmd = new SqlCommand(query.ToString(), this.SqlConnection))
            {
                SqlCommandHelper.AddSqlParameter(cmd, ParameterDirection.Input, "@name", SqlDbType.NVarChar, name);

                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (!reader.IsDBNull(0))
                        {
                            config.Id = reader.GetInt32(0);
                        }

                        if (!reader.IsDBNull(1))
                        {
                            config.Name = reader.GetString(1);
                        }

                        if (!reader.IsDBNull(2))
                        {
                            config.Value = reader.GetString(2);
                        }
                    }
                }
            }

            return config;
        }