public ActionResult DeletePost(Post post) { var comments = db.Comments.Where(e => e.PostId == post.Id); foreach (var comment in comments) { db.Entry(comment).State = System.Data.EntityState.Deleted; } db.Entry(post).State = System.Data.EntityState.Deleted; db.SaveChanges(); return RedirectToAction("Posts"); }
public ActionResult Post(Post post) { var user = db.Users.Where(e => e.UserName == HttpContext.User.Identity.Name).FirstOrDefault(); post.UserId = user.Id; post.DateCreated = DateTime.Now; post.DateModified = DateTime.Now; db.Entry(post).State = System.Data.EntityState.Added; db.SaveChanges(); return RedirectToAction("Posts"); }
public ActionResult EditPost(Post post) { post.DateModified = DateTime.Now; db.Entry(post).State = System.Data.EntityState.Modified; db.SaveChanges(); return RedirectToAction("Posts"); }