Exemplo n.º 1
0
        /// <summary>
        /// 記事を取得します
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool SearchArticle(int id)
        {
            bool result = false;
            if (id < 1)
            {
                return result;
            }

            try
            {
                using (HNKArticleResource resource = new HNKArticleResource(AppSettings.GetDbConnectionString()))
                {
                    Article article = resource.GetArticle(id, PublicStatus.Private);
                    if (article != null && article.Id > 0)
                    {
                        this.Id = article.Id;
                        this.OpenDateTime.Value = article.OpenDate;
                        this.CloseDateTime.Value = article.CloseDate;
                        this.Title = article.Title;
                        this.Body = article.BodyRaw;
                        this.PublicStatus = article.PublicStatus;
                        this.Format = article.Format;
                        this.CategoryId = article.Category.Id;
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
            }

            return result;
        }
Exemplo n.º 2
0
        public void ID指定で特定のブログ記事を取得する()
        {
            try
            {
                this.TestContext.WriteLine("データベースにテストデータをインサートします");
                using (DataResource resource = new DataResource(TestConfig.GetDbConnectionString()))
                {
                    string filePath = Path.Combine(TestConfig.SqlDir, "GetPublicArticles", "insert1.sql");

                    string sql = string.Empty;
                    using (StreamReader reader = new StreamReader(filePath))
                    {
                        sql = reader.ReadToEnd();
                    }

                    if (!string.IsNullOrEmpty(sql))
                    {
                        using (SqlCommand cmd = new SqlCommand(sql, resource.SqlConnection))
                        {
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                this.TestContext.WriteLine(e.ToString());
                Assert.Fail(e.ToString());
            }

            int id = 1;
            Article article = null;
            try
            {
                using (HNKArticleResource resource = new HNKArticleResource(TestConfig.GetDbConnectionString()))
                {
                    article = resource.GetArticle(id);
                }
            }
            catch (Exception e)
            {
                Assert.Fail(e.ToString());
            }

            Assert.IsNotNull(article, "データベースから記事を取得できていない");
            Assert.IsTrue(article.PublicStatus == PublicStatus.Public, "未公開記事を取得している");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 公開可能な記事を取得します
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private Article GetPublicArticle(int id)
        {
            Article article = new Article();

            if (id < 1)
            {
                return article;
            }

            try
            {
                using (HNKArticleResource resource = new HNKArticleResource(AppSettings.GetDbConnectionString()))
                {
                    article = resource.GetArticle(id);
                }
            }
            catch (Exception e)
            {
                AzureLog.WriteToTable(e);
            }

            string[] delimiter = { "," };
            string[] tagIdsStr = article.TagIds.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
            if (tagIdsStr.Length > 0)
            {
                List<int> tagIdsInt = new List<int> { };
                foreach (string tagIdStr in tagIdsStr)
                {
                    int tagIdInt = 0;
                    bool ret = int.TryParse(tagIdStr, out tagIdInt);
                    if (ret)
                    {
                        tagIdsInt.Add(tagIdInt);
                    }
                }

                try
                {
                    using (HNKTagResource resource = new HNKTagResource(AppSettings.GetDbConnectionString()))
                    {
                        List<HNKTag> tags = resource.GetTags(tagIdsInt);
                        if (tags != null && tags.Count > 0)
                        {
                            article.Tags = tags;
                        }
                    }
                }
                catch (Exception e)
                {
                    AzureLog.WriteToTable(e);
                }
            }

            return article;
        }