コード例 #1
0
 public ActionResult Edit(Post post)
 {
     if (ModelState.IsValid)
     {
         db.Entry(post).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(post);
 }
コード例 #2
0
        public ActionResult Create(Post post)
        {
            if (ModelState.IsValid)
            {
                db.Posts.Add(post);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(post);
        }
コード例 #3
0
 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();
     }
 }