コード例 #1
0
 [HttpGet]//metodo abrir eliminar
 public ActionResult Delete(int idpost)
 {
     using (var db = new BlogContext())
     {
         PostB post = db.Post.First(p => p.Id == idpost);
         return(View(post));
     }
 }
コード例 #2
0
 [HttpPost]//metodo eliminar post
 public ActionResult Delete(PostB post)
 {
     using (var db = new BlogContext())
     {
         db.Post.Remove(post);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
コード例 #3
0
 [HttpPost] //Metodo que guarda al editar y agregar nuevo
 public ActionResult AddEdit(PostB post)
 {
     using (var db = new BlogContext())
     {
         if (post.Id == 0)
         {
             db.Post.Add(post);
             db.SaveChanges();
         }
         else
         {
             PostB postBlog = db.Post.First(p => p.Id == post.Id);
             postBlog.Title   = post.Title;
             postBlog.Content = post.Content;
             //postBlog.Date = DateTime.Now.ToString("dd/MM/yyyy");
         }
     }
     return(RedirectToAction("Index"));
 }