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