public ActionResult Create(tMessageCode mescode, tForumTitle title, tForumMessage message) { if (Request.Cookies["account"] == null) { return(RedirectToAction("Index", "ForumHome")); } string epid = Request.Cookies["account"].Value; var EP_ID = db.tEmployee.Where(p => p.fEp_Code == epid).Single().fEp_ID; db.tMessageCode.Add(mescode); db.SaveChanges(); title.fMC_ID = db.tMessageCode.AsEnumerable().Last().fMC_ID; title.fEp_ID = EP_ID; title.fFT_Date = DateTime.Now; message.fEp_ID = EP_ID; message.fFM_Date = DateTime.Now; message.fMC_ID = db.tMessageCode.AsEnumerable().Last().fMC_ID; db.tForumTitle.Add(title); db.tForumMessage.Add(message); db.SaveChanges(); return(RedirectToAction("Index", "ForumHome")); }
//文章內部得細項 public ActionResult Detail(int?id = 10) { //接著透過cookie找出會員編號,確認讀讚人數 if (Request.Cookies["account"] != null) { string epid = Request.Cookies["account"].Value; var EP_ID = db.tEmployee.Where(p => p.fEp_Code == epid).Single().fEp_ID; ViewBag.EPIP = EP_ID; } var ftID = db.tForumTitle.Where(p => p.fMC_ID == id).First().fFT_ID; var addPOP = db.tForumTitle.Where(p => p.fMC_ID == id).First().fFT_Popul; tForumTitle updatePopul = db.tForumTitle.Find(ftID); updatePopul.fFT_Popul = updatePopul.fFT_Popul + 1; db.Entry(updatePopul).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //讀取Detail ForumModel vm = new ForumModel(); vm.Fclass = db.tForumClass.Where(p => p.fFC_Dad == null); vm.pushGood = db.tPushGood; vm.Fmessage = db.tForumMessage.Where(p => p.fMC_ID == id); vm.Ftitle = db.tForumTitle.Where(p => p.fMC_ID == id); vm.employees = db.tEmployee.Where(p => p.tForumMessage.First().fMC_ID == id); return(View(vm)); }
//刪除文章 public ActionResult Delete(int?id) { var FTid = db.tForumTitle.Where(p => p.fMC_ID == id).Single().fFT_ID; var FMid = db.tForumMessage.Where(p => p.fMC_ID == id).Single().fFM_ID; tMessageCode deleCode = db.tMessageCode.Find(id); tForumTitle deleTitle = db.tForumTitle.Find(FTid); tForumMessage deleMessage = db.tForumMessage.Find(FMid); db.tMessageCode.Remove(deleCode); db.tForumTitle.Remove(deleTitle); db.tForumMessage.Remove(deleMessage); db.SaveChanges(); return(RedirectToAction("Index", "ForumMyself")); }