public bool SavePost(BlogPost post) { try { //abre una conexión por el momento que se use el objeto using (var db = new cursonetEntities()) { db.BlogPosts.Add(post); db.SaveChanges(); return(true); } } catch (Exception e) { Console.WriteLine(e.ToString()); throw; } }
public bool deletePost(int id) { BlogPost blogPost = new BlogPost(); try { using (var db = new cursonetEntities()) { blogPost = db.BlogPosts.ToList().Where(i => i.Id == id).FirstOrDefault(); db.BlogPosts.Remove(blogPost); db.SaveChanges(); } return(true); } catch (Exception) { return(false); } }