Exemplo n.º 1
0
        public int GetMostRecentBlogPost()
        {
            using var ctx = new BlogsiteDbContext(_connectionString);
            BlogPost post = ctx.BlogPosts.Include(p => p.Comments).OrderByDescending(p => p.DatePosted).FirstOrDefault();

            return(post.Id);
        }
Exemplo n.º 2
0
        public int GetLastPage()
        {
            var ctx   = new BlogsiteDbContext(_connectionString);
            var total = ctx.BlogPosts.Count();

            if (total % 3 == 0)
            {
                return(total / 3);
            }

            return((total / 3) + 1);
        }
Exemplo n.º 3
0
 public BlogPost GetById(int id)
 {
     using var ctx = new BlogsiteDbContext(_connectionString);
     return(ctx.BlogPosts.Include(p => p.Comments).FirstOrDefault(p => p.Id == id));
 }
Exemplo n.º 4
0
 public List <BlogPost> GetAll(int page)
 {
     using var ctx = new BlogsiteDbContext(_connectionString);
     return(ctx.BlogPosts.Include(p => p.Comments).OrderByDescending(p => p.DatePosted).Skip((page - 1) * 3).Take(3).ToList());
 }
Exemplo n.º 5
0
 public int GetPostsCount()
 {
     using var ctx = new BlogsiteDbContext(_connectionString);
     return(ctx.BlogPosts.Count());
 }
Exemplo n.º 6
0
 public void AddComment(Comment comment)
 {
     using var ctx = new BlogsiteDbContext(_connectionString);
     ctx.Comments.Add(comment);
     ctx.SaveChanges();
 }
Exemplo n.º 7
0
 public void AddBlogpost(BlogPost blogpost)
 {
     using var ctx = new BlogsiteDbContext(_connectionString);
     ctx.BlogPosts.Add(blogpost);
     ctx.SaveChanges();
 }