public ActionResult Edit(Post post) { if (ModelState.IsValid) { db.Entry(post).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(post); }
public ActionResult Create(Post post) { if (ModelState.IsValid) { db.Posts.Add(post); db.SaveChanges(); return RedirectToAction("Index"); } return View(post); }
public void DadoQueEuTenhoUmPost() { using (var blogContext = new BlogContext()) { foreach (var jaEraPost in blogContext.Posts) { blogContext.Posts.Remove(jaEraPost); } post = new Post {Titulo = "Ola", Corpo = "Bem vindo", Data = new DateTime(2012, 2, 3), Autor = "Giovanni Bassi"}; blogContext.Posts.Add(post); blogContext.SaveChanges(); } }