//Select Post by Id public tForum queryPostById(int fPostId) { //TODO - 補上權限控制 tForum result = (from i in db.tForums where i.fPostId == fPostId select i).FirstOrDefault(); return(result); }
//修改文章內容 public ActionResult Edit(int fPostId) { Session[CDictionary.UPDATE_FORUM_ID] = fPostId; CForum forum = new CForum(); tForum tForum = forum.queryPostById(fPostId); if (tForum != null) { return(View(tForum)); } return(RedirectToAction("List")); }
//Delete Post By Id public void deletePostById(int fPostId) { tForum result = (from i in db.tForums where i.fPostId == fPostId && i.fEnableFlag == true select i).FirstOrDefault(); if (result != null) { result.fEnableFlag = false; result.fEnableUserId = 1; //TODO - 要動態產生 result.fDisableTime = DateTime.Now; db.SaveChanges(); } }
//Update Post By Id public void updatePostById(object fPostId, CForumCreate data) { int fId = Convert.ToInt32(fPostId); tForum result = (from i in db.tForums where i.fPostId == fId select i).FirstOrDefault(); if (result != null) { result.fPostTitle = data.postTitle; result.fPostContent = data.tmpContent; result.fUpdateTime = DateTime.Now; db.SaveChanges(); } }
//Create New Post public void newPost(int userId, string title, string content) { tForum newForumRecord = new tForum(); newForumRecord.fId = userId; newForumRecord.fPostTitle = title; newForumRecord.fPostContent = content; newForumRecord.fIsPost = true; newForumRecord.fCreateTime = DateTime.Now; newForumRecord.fUpdateTime = DateTime.Now; newForumRecord.fEnableFlag = true; newForumRecord.fTopSeq = 999; newForumRecord.fTotalReplyCount = 0; newForumRecord.fTotalViewCount = 0; db.tForums.Add(newForumRecord); db.SaveChanges(); }
//呈現文章的內容 public ActionResult PostView(int fPostId) { //一進入Action就先取出當下時間 ViewBag.DateTime = DateTime.Now.ToString("yyyyMMddHHmmssfff"); CForum forum = new CForum(); tForum tForum = forum.queryPostById(fPostId); CReply reply = new CReply(); List <List <tForumReply> > replys = reply.getReplysById(fPostId); CPostView postview = new CPostView { forum = tForum, reply = replys }; if (postview.forum != null) { string test = postview.forum.fPostContent; return(View(postview)); } return(RedirectToAction("List")); }