public PartialViewResult _NewArticle() { HomeViewModel viewModel = new HomeViewModel(); List <article_Tb> articleList = new List <article_Tb>(); List <board_Tb> boardList = new List <board_Tb>(); List <user_Tb> userList = new List <user_Tb>(); //標題字數 articleList = Service_Article_P.ListArticle_Md(null, null).OrderByDescending(m => m.arti_date).Take(5).ToList(); viewModel.articleList = articleList; for (int i = 0; i < articleList.Count(); i++) { articleList[i].title = Method.StrSubstring(articleList[i].title, 0, 50); articleList[i].arti_txt = Method.StrSubstring(articleList[i].arti_txt, 0, 100); boardList.Add(new board_Tb() { id = (int)articleList[i].arti_theme, theme_board_id = articleList[i].board_id, board_name = Service_Board_P.GetBoardName_Md(articleList[i].board_id) }); userList.Add(new user_Tb() { user_id = articleList[i].user_id, username = Service_User_P.GetUserInfo_Md(articleList[i].user_id).username }); } viewModel.articleList = articleList; viewModel.boardList = boardList; viewModel.userInfoList = userList; return(PartialView(viewModel)); }
/// <summary> /// 討論版文章列表 /// </summary> /// <param name="board"></param> /// <param name="theme"></param> /// <returns></returns> public ActionResult BoardArticle(int?board, int?theme) { HomeViewModel viewModel = new HomeViewModel(); List <board_Tb> themeItems = new List <board_Tb>(); viewModel.boardItem = new board_Tb(); //如果board參數無值以及負數導向首頁 Method.ValueIsEmpty(board); if (Method.ValueIsEmpty_Val || board < 0) { return(RedirectToAction("Index", "Home")); } ViewBag.boardId = board; //如果theme參數無值以及負數導向該版全部主題 Method.ValueIsEmpty(theme); if (Method.ValueIsEmpty_Val || theme < 0) { theme = 0; } //目前討論版資訊 viewModel.boardItem.id = (int)board; viewModel.boardItem.board_name = Service_Board_P.GetBoardName_Md((int)board); //獲取討論版分類項目 themeItems = Service_Board_P.ListTheme_Md((int)board); viewModel.boardList = themeItems; //獲取全部主題或該項目文章列表 List <article_Tb> articleItems = new List <article_Tb>(); articleItems = (theme != 0) ? Service_Article_P.ListArticle_Md(board, theme).OrderByDescending(m => m.arti_date).ToList() : Service_Article_P.ListArticle_Md(board, null).OrderByDescending(m => m.arti_date).ToList(); viewModel.articleList = articleItems; List <user_Tb> userItems = new List <user_Tb>(); viewModel.replyCountList = new List <int>(); //各文章回覆數量 for (int i = 0; i < articleItems.Count(); i++) { articleItems[i].title = Method.StrSubstring(articleItems[i].title, 0, 50); articleItems[i].arti_txt = Method.StrSubstring(articleItems[i].arti_txt, 0, 100); int sum = Service_Article_P.GetArticleReplyCount_Md(articleItems[i].arti_id); viewModel.replyCountList.Add(sum); userItems.Add(Service_User_P.GetUserInfo_Md(articleItems[i].user_id)); } viewModel.userInfoList = userItems; return(View(viewModel)); }