public int GetMostRecentPostId() { using var ctx = new BlogDataContext(_connectionString); return(ctx.Posts.OrderByDescending(p => p.DatePosted).Select(p => p.Id).FirstOrDefault()); }
public void AddComment(Comment comment) { using var ctx = new BlogDataContext(_connectionString); ctx.Comments.Add(comment); ctx.SaveChanges(); }
public Post GetPostById(int id) { using var ctx = new BlogDataContext(_connectionString); return(ctx.Posts.Include(p => p.Comments).FirstOrDefault(p => p.Id == id)); }
public int GetTotalPostCount() { using var ctx = new BlogDataContext(_connectionString); return(ctx.Posts.Count()); }
public List <Post> GetPosts() { using var ctx = new BlogDataContext(_connectionString); return(ctx.Posts.OrderByDescending(p => p.DatePosted).Include(p => p.Comments).ToList()); }
public void AddPost(Post post) { using var ctx = new BlogDataContext(_connectionString); ctx.Posts.Add(post); ctx.SaveChanges(); }