public async Task <IHttpActionResult> GetComments(string id, int offset = 0, int limit = 20) { offset = Math.Max(0, offset); limit = Math.Min(100, limit); var decodedId = id.FromEncodedId(); var post = await _dbContext.Posts.FirstOrDefaultAsync(p => p.Id == decodedId); if (post == null) { return(NotFound()); } var max = await _dbContext.Entry(post) .Collection(p => p.Comments) .Query() .CountAsync(); var comments = await _dbContext.Entry(post) .Collection(p => p.Comments) .Query() .OrderByDescending(p => p.Id) .Skip(offset) .Take(limit) .ToListAsync(); return(OkPageData(await _dtoService.CreateListAsync <Comment, DtoComment>(comments), offset + limit < max)); }
public async Task <IHttpActionResult> Get( Country country, int offset = 0, int limit = 20) { offset = Math.Max(0, offset); limit = Math.Min(100, limit); var max = await _dbContext.Categories.CountAsync(); var categories = await _dbContext.Categories .Where(p => p.Country == country) .OrderByDescending(p => p.Posts.Count(m => m.DeletedAt == null)) .ThenBy(p => p.Title) .Skip(offset) .Take(limit) .ToListAsync(); return(OkPageData(await _dtoService.CreateListAsync <Category, DtoCategory>(categories), offset + limit < max)); }