public new Models.BlogPost Get(long id) { return(DbSet_ .Include(x => x.Comments) .Include(x => x.Author) .FirstOrDefault(x => x.Id == id)); }
public IEnumerable <Models.Comment> GetCommentsPage(long postId, int page, int onPage) { if (page > GetCommentsPageCount(postId, onPage)) { return(null); } return(DbSet_ .Where(x => x.PostId == postId) .OrderByDescending(x => x.PostingTime) .Skip(onPage * (page - 1)).Take(onPage) .ToList()); }
public IEnumerable <Models.BlogPost> GetPage(int page, int onPage) { int skippedCount = onPage * (page - 1); int postCount = DbSet_.Count(); if (page > GetPageCount(onPage)) { return(null); } if (postCount == 0) { return(new List <Models.BlogPost>()); } return(DbSet_.OrderByDescending(x => x.PostingTime) .Skip(skippedCount) .Take(Math.Min(onPage, postCount - skippedCount)) .Include(x => x.Author) .Include(x => x.Comments) .ToList()); }
public int GetCommentsPageCount(long postId, int onPage) { int count = DbSet_.Where(x => x.PostId == postId).Count(); return(count / onPage + (count % onPage == 0 ? 0 : 1)); }
public int GetPageCount(int onPage) { int count = DbSet_.Count(); return(count / onPage + count % onPage == 0 ? 0 : 1); }