public ActionResult DelPost(int id) { DB db = new DB(); Post posts = new Post(); posts = (from p in db.Posts where p.ID == id select p).FirstOrDefault(); db.Posts.Remove(posts); db.SaveChanges(); return Redirect("/Admin/ManagePost"); }
public ActionResult ManagePost() { if (this.HttpContext.Session["User"] == null) return Redirect("/Admin/Login"); else { DB db = new DB(); List<Post> posts = new List<Post>(); posts = (from p in db.Posts select p).ToList(); int counts = posts.Count(); ViewData["counts"] = counts; ViewBag.posts = posts; return View(); } }
public ActionResult Index() { DB db = new DB(); List<Post> posts = new List<Post>(); List<vPost> vposts = new List<vPost>(); posts = (from p in db.Posts orderby p.ID descending select p).ToList(); foreach (Post post in posts) { vPost vpost = new vPost(post); vposts.Add(vpost); } ViewBag.posts = vposts; return View(); }
public ActionResult Login(string username , string password) { DB db = new DB(); User user = new User(); //user = // (from U in db.Users // where username == U.Name && password == U.Password // select U).FirstOrDefault(); user = (db.Users.Where(u => u.Password == password && u.Name == username)).FirstOrDefault(); if (user != null) { this.HttpContext.Session["User"] = username; return Redirect("/Admin/Home/Index"); } else { return Redirect("/Admin/Error"); } }
public ActionResult Index(int page) { DB db = new DB(); int index = page * 10; List<Post> posts = new List<Post>(); List<vPost> vposts = new List<vPost>(); posts = (from p in db.Posts orderby p.ID descending select p).Skip(index).Take(10).ToList(); foreach (Post item in posts) { vposts.Add(new vPost(item)); } AjaxModel ajaxModel = new AjaxModel(); try { if (vposts.Count() == 0) { ajaxModel.Data = ""; ajaxModel.Statu = "end"; ajaxModel.Msg = "没有更多了"; } else { ajaxModel.Data = vposts; ajaxModel.Statu = "OK"; ajaxModel.Msg = "加载成功"; } } catch { ajaxModel.Statu = "err"; ajaxModel.Msg = "获取失败"; } return Json(ajaxModel); }
public ActionResult Message() { DB db = new DB(); List<Message> messages = new List<Message>(); messages = (from m in db.messages select m).ToList(); ViewBag.messages = messages; return View(); }
public ActionResult RevPost(int id) { DB db = new DB(); Post posts = new Post(); posts = (from p in db.Posts where p.ID == id select p).FirstOrDefault(); return Redirect("/Admin/ManagePost"); }
public ActionResult Register(string username , string password , string rpassword) { DB db = new DB(); User user = new User(); user.Name = username; user.Password = password; db.Users.Add(user); int row = db.SaveChanges(); if (row > 0) { return Redirect("/Admin/Login"); } else { return Redirect("/Admin/Error"); } }
public ActionResult PublicPosts(string title, string content, string classify) { DB db = new DB(); Post posts = new Post(); posts.Title = title; posts.Content = content; posts.Classify = classify; posts.DateOfIssue = DateTime.Now; posts.Author = "尹逸朋"; db.Posts.Add(posts); int row = db.SaveChanges(); if (row > 0) { return Redirect("/Admin/Home/PublicPosts"); } else { return Redirect("/Admin/Error"); } }
public ActionResult PostMore(int id) { DB db = new DB(); List<Post> posts = new List<Post>(); List<vPost> vposts = new List<vPost>(); posts = (from p in db.Posts select p).ToList(); foreach (Post post in posts) { vPost vpost = new vPost(post); vposts.Add(vpost); } ViewBag.posts = vposts; List<Post> postList = new List<Post>(); postList = (from l in db.Posts orderby l.Browse descending select l).ToList(); ViewBag.postList = postList; Post post2 = new Post(); post2 = (from p in db.Posts where p.ID == id select p).FirstOrDefault(); post2.Browse++; db.SaveChanges(); ViewData["id"] = post2.ID; ViewData["title"] = post2.Title; ViewData["content"] = post2.Content; List<PostReply> postreply = new List<PostReply>(); postreply = (from p in db.PostReply where p.PostID == id select p).ToList(); ViewBag.postreply = postreply; return View(); }
//慢生活 public ActionResult Slive() { DB db = new DB(); List<Post> posts = new List<Post>(); List<vPost> vPosts = new List<vPost>(); posts = (from p in db.Posts orderby p.ID descending select p).ToList(); foreach (Post post in posts) { vPost vpost = new vPost(post); vPosts.Add(vpost); } ViewBag.posts = vPosts; List<Post> postList = new List<Post>(); postList = (from l in db.Posts orderby l.Browse descending select l).ToList(); ViewBag.postList = postList; return View(); }
public ActionResult PostMore_reply(int id, string content) { DB db = new DB(); PostReply postreply = new PostReply(); postreply.PostID = id; postreply.ReplyContent = content; postreply.DateOfIssue = DateTime.Now; db.PostReply.Add(postreply); int row = db.SaveChanges(); if (row > 0) { return Redirect("/Home/Index"); } else { return Redirect("/Home/Error"); } }