public ActionResult MyWords() { int UserId = (int)Session["UserId"]; var gb = from u in db.Guestbooks where u.IsPass == true && u.UserId == UserId orderby u.CreatedOn descending select u;
return View("MyWords", gb.ToList()); }
public ActionResult Delete(int id) { var gb = db.Guestbooks.Find(id); return View(gb); }
[HttpPost, ActionName("Delete")] public ActionResult DeleteConfired(int id) { var gb = db.Guestbooks.Find(id); db.Guestbooks.Remove(gb); db.SaveChanges(); return RedirectToAction("MyWords", "User"); }
public ActionResult DeleteIndex() { var gb = from u in db.Guestbooks where u.IsPass == true orderby u.CreatedOn descending select u; return View(gb.ToList()); } public ActionResult Delete(int id) { var gb = db.Guestbooks.Find(id); return View(gb); }
[HttpPost, ActionName("Delete")] public ActionResult DeleteConfired(int id) { var gb = db.Guestbooks.Find(id); db.Guestbooks.Remove(gb); db.SaveChanges(); return RedirectToAction("DeleteIndex","Admin");
public ActionResult CheckIndex() { var gb = from u in db.Guestbooks where u.IsPass == false orderby u.CreatedOn descending select u;
return View("CheckIndex", gb.ToList()); }
public ActionResult CheckMessage(int id) { var gb = db.Guestbooks.Find(id); return View(gb); } [HttpPost, ActionName("CheckMessage")] public ActionResult CheckMessage1(int id)//通过审核方法 { var gb = db.Guestbooks.Find(id); gb.IsPass = true; db.SaveChanges(); return RedirectToAction("CheckIndex", new { target = "fc" }); }
管理员点击审核通过后,执行方法,将 IsPass 设置为 True,主页就可以正常显示该留言了。
用户管理
Admin
UserManger
DeleteUser
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
public ActionResult UserManage() { var user = from u in db.Users select u; return View("UserManage", user.ToList()); }
public ActionResult DeleteUser(int id) { User user = db.Users.Find(id); if (user != null) { db.Users.Remove(user); db.SaveChanges(); } return RedirectToAction("UserManage"); }
选择所有用户,遍历每一行,显示在页面上,删除同删除留言,通过主键删除。
留言统计
Admin
CommentSummary
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
public ActionResult CommentSummary() { var gb = from u in db.Guestbooks where u.IsPass == true orderby u.CreatedOn descending select u; int count = gb.Count();
var gb2 = from u in db.Guestbooks where u.IsPass == false orderby u.CreatedOn descending select u; int count2 = gb2.Count();