public List<Post> GetAllPosts() { using (var db = new BlogContext()) { var posts = db.Posts.ToList(); return posts; } }
public void ClearPosts() { if (GetAllPosts().Any()) { using (var db = new BlogContext()) { db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Post]"); } } }
public ActionResult Create(Post post) { post.Author = Application.CurrentUser.Name; post.State = "Draft"; using (var db = new BlogContext()) { db.Posts.Add(post); db.SaveChanges(); } return RedirectToAction("Index"); }
public UnitOfWork(BlogContext blogContext) { _blogContext = blogContext; }
public UserRepository(BlogContext context) : base(context) { }