public ActionResult Create() { ViewData["CategoryId"] = new SelectList(db.Categories, "Id", "Name"); ViewData["AuthorId"] = new SelectList(db.Users, "Id", "Email"); AddAvailableTags(); return(View(PostModel.FromEntity(new Post()))); }
// GET: Latest public ActionResult Latest() { IQueryable <Post> latestPosts = db.Posts. Where(post => post.Visible). OrderByDescending(post => post.AddedOn). Take(5); return(View("List", PostModel.FromEntity(latestPosts))); }
// GET: View public ActionResult View(int id) { Post post = db.Posts.Where(item => item.Visible && item.Id == id).FirstOrDefault(); if (post == null) { return(HttpNotFound()); } return(View(PostModel.FromEntity(post))); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Post post = db.Posts.Find(id); if (post == null) { return(HttpNotFound()); } return(View(PostModel.FromEntity(post))); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Post post = db.Posts.Find(id); if (post == null) { return(HttpNotFound()); } ViewData["CategoryId"] = new SelectList(db.Categories, "Id", "Name", post.CategoryId); ViewData["AuthorId"] = new SelectList(db.Users, "Id", "Email", post.AuthorId); AddAvailableTags(); return(View(PostModel.FromEntity(post))); }
// GET: All public ActionResult All(int?category = null, int?tag = null) { IQueryable <Post> allPosts = db.Posts. Where(post => post.Visible). OrderByDescending(post => post.AddedOn); if (category.HasValue) { allPosts = allPosts.Where(post => post.CategoryId == category.Value); ViewData["CurrentCategory"] = db.Categories.Find(category.Value); } if (tag.HasValue) { allPosts = allPosts.Where(post => post.Tags. Where(innerTag => innerTag.Id == tag.Value). Count() > 0); ViewData["CurrentTag"] = db.Tags.Find(tag.Value); } return(View("List", PostModel.FromEntity(allPosts))); }
public ActionResult Index() { var posts = db.Posts.Include(p => p.Category).Include(p => p.User); return(View(PostModel.FromEntity(posts))); }