public ActionResult Edit(Post modifiedPost) { var blogEntities = new BlogEntities(); var postID = modifiedPost.ID; var originalPost = GetPostByID(postID); if (!ModelState.IsValid) { return View(originalPost); } blogEntities.Attach(originalPost); blogEntities.ApplyCurrentValues(originalPost.EntityKey.EntitySetName, modifiedPost); blogEntities.SaveChanges(); return RedirectToRouteResult(postID); }
public ActionResult Create(Post post) { if (String.IsNullOrEmpty(post.Title) || String.IsNullOrEmpty(post.Text)) { return View(); } post.ID = Guid.NewGuid(); post.Posted = DateTime.Now; post.Index = post.Title; var blogEntities = new BlogEntities(); blogEntities.AddToPosts(post); blogEntities.SaveChanges(); return RedirectToRouteResult(post.ID); }
public ActionResult Delete(Guid postID) { var postByID = GetPostByID(postID); var blogEntities = new BlogEntities(); blogEntities.Attach(postByID); blogEntities.DeleteObject(postByID); blogEntities.SaveChanges(); return RedirectToAction("Index"); }