public ActionResult Edit(int id, Blog blog) { try { _context.Entry(blog).State = System.Data.EntityState.Modified; _context.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Create(Blog newBlog) { try { newBlog.DateCreated = DateTime.Now; using (_context) { _context.Blogs.Add(newBlog); _context.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult EditwithConcurrencyCheck(int id, Blog blog, string originalName) { try { _context.Entry(blog).State = System.Data.EntityState.Modified; // Concurrency Check with Blogger name. Change the Edit Get view to send original Blogger name as an hidden Field _context.Entry(blog).Property(b => b.BloggerName).OriginalValue = originalName; _context.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Delete(int id, Blog blog) { try { using (_context) { _context.Entry(blog).State = System.Data.EntityState.Deleted; _context.SaveChanges(); } return RedirectToAction("Index"); } catch { return View(); } }