/// <summary> /// タグを取得します /// </summary> /// <param name="dbConnectionString">接続文字列</param> /// <returns>タグのリスト</returns> public static List<HNKTag> GetTags(string dbConnectionString) { List<HNKTag> tags = new List<HNKTag> { }; using (HNKTagResource resource = new HNKTagResource(dbConnectionString)) { tags = resource.GetAll(); } return tags; }
/// <summary> /// 指定されたタグを取得します /// </summary> /// <param name="dbConnectionString">接続文字列</param> /// <param name="id">タグID</param> /// <returns>タグ</returns> public static HNKTag GetCategory(string dbConnectionString, int id) { HNKTag tag = null; using (HNKTagResource resource = new HNKTagResource(dbConnectionString)) { tag = resource.GetTag(id); } return tag; }
/// <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; }
/// <summary> /// トップページを表示します /// </summary> /// <param name="args"></param> /// <returns></returns> public ActionResult Index(VMHome args) { HNKBlogConfigManager cfgMgr = null; try { cfgMgr = new HNKBlogConfigManager(AppSettings.GetDbConnectionString()); } catch (Exception e) { AzureLog.WriteToTable(e); return new HttpStatusCodeResult(500); } args.BlogDescription = cfgMgr.BlogDescription.Value; try { int hitCount = 0; args.PublicArticles = ArticleFetcher.GetArticles(AppSettings.GetDbConnectionString(), args.L, args.P, out hitCount); args.TotalArticleCount = hitCount; args.SetPageTitle(string.Empty, cfgMgr.BlogTitle.Value); } catch (Exception e) { AzureLog.WriteToTable(e); return new HttpStatusCodeResult(500); } foreach (Article article in args.PublicArticles) { 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 View(args); }