// Blogs #region public async Task<BlogsPaged> GetBlogsAsync(int page, int CategoryID) public async Task <BlogsPaged> GetBlogsAsync(int page, int CategoryID) { page = page - 1; BlogsPaged objBlogsPaged = new BlogsPaged(); if (CategoryID == 0) { objBlogsPaged.BlogCount = await _context.Blogs .CountAsync(); objBlogsPaged.Blogs = await _context.Blogs .Include(x => x.BlogCategory) .OrderBy(x => x.BlogDate) .Skip(page * 5) .Take(5).ToListAsync(); } else { objBlogsPaged.BlogCount = await _context.Blogs .Include(x => x.BlogCategory) .Where(x => x.BlogCategory.Any(y => y.CategoryId == CategoryID)) .CountAsync(); objBlogsPaged.Blogs = await _context.Blogs .Include(x => x.BlogCategory) .Where(x => x.BlogCategory.Any(y => y.CategoryId == CategoryID)) .OrderBy(x => x.BlogDate) .Skip(page * 5) .Take(5).ToListAsync(); } return(objBlogsPaged); }
// Blogs #region public async Task<BlogsPaged> GetBlogsAsync(int page, int CategoryID) public async Task <BlogsPaged> GetBlogsAsync(int page, int CategoryID) { page = page - 1; BlogsPaged objBlogsPaged = new BlogsPaged(); if (CategoryID == 0) { objBlogsPaged.BlogCount = await _context.Blogs .CountAsync(); objBlogsPaged.Blogs = await(from blog in _context.Blogs .Include(x => x.BlogCategory) select new Blogs { BlogId = blog.BlogId, BlogTitle = blog.BlogTitle, BlogDate = blog.BlogDate, BlogUserName = blog.BlogUserName, BlogSummary = blog.BlogSummary, BlogContent = blog.BlogSummary, BlogCategory = blog.BlogCategory }).OrderByDescending(x => x.BlogDate).Skip(page * 5).Take(5).ToListAsync(); } else { objBlogsPaged.BlogCount = await _context.Blogs .Include(x => x.BlogCategory) .Where(x => x.BlogCategory.Any(y => y.CategoryId == CategoryID)) .CountAsync(); objBlogsPaged.Blogs = await(from blog in _context.Blogs .Include(x => x.BlogCategory) .Where(x => x.BlogCategory.Any(y => y.CategoryId == CategoryID)) select new Blogs { BlogId = blog.BlogId, BlogTitle = blog.BlogTitle, BlogDate = blog.BlogDate, BlogUserName = blog.BlogUserName, BlogSummary = blog.BlogSummary, BlogContent = blog.BlogSummary, BlogCategory = blog.BlogCategory }).OrderByDescending(x => x.BlogDate).Skip(page * 5).Take(5).ToListAsync(); } return(objBlogsPaged); }
public async Task <BlogsPaged> GetBlogsAdminAsync(string strUserName, int page) { page = page - 1; BlogsPaged objBlogsPaged = new BlogsPaged(); objBlogsPaged.BlogCount = await _context.Blogs .Where(x => x.BlogUserName == strUserName) .AsNoTracking() .CountAsync(); objBlogsPaged.Blogs = await _context.Blogs .Include(x => x.BlogCategory) .Where(x => x.BlogUserName == strUserName) .OrderBy(x => x.BlogDate) .Skip(page * 5) .Take(5).ToListAsync(); return(objBlogsPaged); }