public ActionResult CheckReplyInfo(string article_txt) { Method.ValueIsEmpty(article_txt); //檢查articleId是否空白 Method.ValueIsEmpty(Request.Form["article"]); if (Method.ValueIsEmpty_Val) { TempData[InternalVal._RESULTMSG] = "回覆不可空白!" + Method.RedirectUrl; return(RedirectToAction("ResultMessage", "Home")); } user_Tb userItem = new user_Tb(); userItem = Service_User_P.GetUserInfo_Md(Session[InternalVal._SESSIONACCOUNT].ToString()); article_reply_Tb articleReplyItem = new article_reply_Tb(); articleReplyItem.reply_txt = article_txt; articleReplyItem.reply_date = DateTime.Now; articleReplyItem.reply_update = DateTime.Now; articleReplyItem.arti_id = int.Parse(Request.Form["article"].Trim().ToString()); articleReplyItem.user_id = userItem.user_id; bool result = Service_Article_P.InsertArticleReply_Md(articleReplyItem); //前往回覆的文章 Method.RedirectUrl = "/Article/ReviewArticle" + TempData["ArticleUrl"]; TempData[InternalVal._RESULTMSG] = (result) ? "回覆成功!" : "回覆失敗!"; return(RedirectToAction("ResultMessage", "Home")); }
public ActionResult CheckArticleInfo(string title, string board_id, string theme_id, string article_txt) { Method.ValueIsEmpty(title); Method.ValueIsEmpty(board_id); Method.ValueIsEmpty(theme_id); Method.ValueIsEmpty(article_txt); if (Method.ValueIsEmpty_Val) { return(View("LaunchArticle", (HomeViewModel)Session["ViewModel"])); } //int getBoardId = Service_Board_P.GetBoardIdOfTheme_Md(int.Parse(theme_id.Trim())); int getBoardId = Service_Board_P.GetBoardIdOfTheme_Md(int.Parse(theme_id.Trim())); if (getBoardId != int.Parse(board_id.Trim())) { TempData[InternalVal._RESULTMSG] = "該討論版無此分類!請重新發佈文章!"; return(RedirectToAction("ResultMessage", "Home")); } article_Tb articleItem = new article_Tb() { title = title.Trim(), arti_txt = article_txt.Trim(), board_id = int.Parse(board_id.Trim()), arti_theme = int.Parse(theme_id.Trim()), user_id = Service_User_P.GetUserInfo_Md(Session[InternalVal._SESSIONACCOUNT].ToString()).user_id }; return(RedirectToAction("AddArticle", articleItem)); }
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)); }
public PartialViewResult _RightArticleReply() { HomeViewModel viewModel = new HomeViewModel(); //挑選出有回覆的文章 List <article_Tb> articleItems = Service_Article_P.ListArticle_Md(null, null).Take(5).ToList(); List <article_reply_Tb> articleReplyInfoList = new List <article_reply_Tb>(); List <user_Tb> userInfoList = new List <user_Tb>(); List <int> replyCountList = new List <int>(); List <board_Tb> boardList = new List <board_Tb>(); viewModel.articleList = articleItems; int num = 0; foreach (var item in articleItems) { num = Service_Article_P.GetArticleReplyCount_Md(item.arti_id); if (num > 0) { article_reply_Tb articleReplyInfo = Service_Article_P.ListArticleReply_Md(item.arti_id).OrderByDescending(m => m.reply_id).FirstOrDefault(); articleReplyInfoList.Add(articleReplyInfo); user_Tb userInfo = Service_User_P.GetUserInfo_Md(articleReplyInfo.user_id); userInfoList.Add(userInfo); boardList.Add(new board_Tb { id = (int)item.arti_theme, theme_board_id = item.board_id }); } //獲取當前討論版 string strParameter = ""; // 取得當前網址集合 NameValueCollection nvc = Request.QueryString; var board = nvc["board"]; var theme = nvc["theme"]; if (board != null && theme != null) { strParameter += "?board=" + board + "&theme=" + theme; } else if (board != null && theme == null) { strParameter += "?board=" + board; } ViewBag.urlPara = strParameter; replyCountList.Add(num); } viewModel.replyCountList = replyCountList; viewModel.replyAritlceList = articleReplyInfoList; viewModel.userInfoList = userInfoList; viewModel.boardList = boardList; return(PartialView(viewModel)); }
/// <summary> /// 觀看文章 /// </summary> /// <param name="article"></param> /// <param name="board"></param> /// <param name="theme"></param> /// <returns></returns> public ActionResult ReviewArticle(int?article, int?board, int?theme) { HomeViewModel viewModel = new HomeViewModel(); //文章ID為空直接跳轉至該討論版 Method.ValueIsEmpty(article); if (Method.ValueIsEmpty_Val) { return(RedirectToAction("BoardArticle", new { board = board })); } //討論版ID為空直接跳轉至首頁 Method.ValueIsEmpty(board); if (Method.ValueIsEmpty_Val) { return(RedirectToAction("Index", "Home")); } article_Tb articleItem = new article_Tb(); articleItem = Service_Article_P.GetArticle_Md((int)article); //檢查該筆文章是否符合 if (articleItem.arti_id != article || articleItem.board_id != board || articleItem.arti_theme != theme) { TempData[InternalVal._RESULTMSG] = "無該筆文章!"; return(RedirectToAction("ResultMessage", "Home")); } //獲取當前的URL參數 TempData["ArticleUrl"] = Request.Url.Query; TempData["ArticleQueryString"] = Request.QueryString; //文章內容資訊 viewModel.articleItem = articleItem; viewModel.replyCount = Service_Article_P.GetArticleReplyCount_Md((int)article); viewModel.boardItem = new board_Tb() { id = (int)board, board_name = Service_Board_P.GetBoardName_Md((int)board) }; viewModel.userItem = Service_User_P.GetUserInfo_Md(articleItem.user_id); //文章回覆 List <article_reply_Tb> replyArticleItems = Service_Article_P.ListArticleReply_Md((int)article).ToList(); viewModel.replyAritlceList = replyArticleItems; List <user_Tb> userItems = new List <user_Tb>(); for (int i = 0; i < replyArticleItems.Count(); i++) { userItems.Add(Service_User_P.GetUserInfo_Md(replyArticleItems[i].user_id)); } viewModel.userInfoList = userItems; return(View(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)); }
public ActionResult EditReply(int replyId, int board, int theme, string account) { Method.ValueIsEmpty(replyId); Method.ValueIsEmpty(account); if (Method.ValueIsEmpty_Val) { TempData[InternalVal._RESULTMSG] = "回覆資訊有誤!"; return(RedirectToAction("ResultMessage", "Home")); } article_reply_Tb replyArticle = new article_reply_Tb(); replyArticle = Service_Article_P.GetArticleReply_Md(replyId); user_Tb user = new user_Tb(); user = Service_User_P.GetUserInfo_Md(replyArticle.user_id); HomeViewModel viewModel = new HomeViewModel(); viewModel.replyAritlceItem = replyArticle; viewModel.userItem = user; return(View(viewModel)); }
public PartialViewResult _LeftHotArticle() { 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>(); List <article_reply_Tb> articleReplyList = new List <article_reply_Tb>(); articleList = Service_Article_P.ListArticle_Md(null, null).OrderByDescending(m => m.view_num).ThenByDescending(m => m.arti_id).Take(5).ToList(); //文章最新回覆的用戶ID article_reply_Tb articleReplyItem = new article_reply_Tb(); user_Tb userItem = new user_Tb(); for (int i = 0; i < articleList.Count(); i++) { //標題字數 articleList[i].title = Method.StrSubstring(articleList[i].title, 0, 30); //討論版名稱 boardList.Add(new board_Tb() { id = (int)articleList[i].arti_theme, board_name = Service_Board_P.GetBoardName_Md(articleList[i].board_id), theme_board_id = articleList[i].board_id }); articleReplyItem = Service_Article_P.ListArticleReply_Md(articleList[i].arti_id).OrderByDescending(m => m.reply_id).FirstOrDefault(); if (articleReplyItem != null) { userItem = Service_User_P.GetUserInfo_Md(articleReplyItem.user_id); userList.Add(userItem); articleReplyList.Add(articleReplyItem); } } viewModel.articleList = articleList; viewModel.boardList = boardList; viewModel.userInfoList = userList; viewModel.replyAritlceList = articleReplyList; return(PartialView(viewModel)); }