public async Task <ActionResult <IEnumerable <TextDto> > > GetTexts([FromQuery] TextResourceParameters textRequest) { IEnumerable <TextDto> textFromRepo; int totalCount; if (!IsNullOrWhiteSpace(textRequest.Category)) { textFromRepo = await _textService.GetTextsCategoryAsync(textRequest); totalCount = await _textService.GetTotalCountCategory(textRequest.Category); } else if (!IsNullOrWhiteSpace(textRequest.Author)) { textFromRepo = await _textService.GetTextsAuthorAsync(textRequest); totalCount = await _textService.GetTotalCountAuthor(textRequest.Author); } else { textFromRepo = await _textService.GetTextsAsync(textRequest); totalCount = await _textService.GetTotalCount(); } Response.Headers.Add("Access-Control-Expose-Headers", "X-Total-Count"); Response.Headers.Add("X-Total-Count", totalCount.ToString()); return(Ok(_mapper.Map <IEnumerable <TextDto> > (textFromRepo))); }
public async Task <IEnumerable <TextDto> > GetTextsAsync(TextResourceParameters textRequest) { var texts = await _context.Texts .Include(s => s.Sentences) .ThenInclude(w => w.Words) .OrderByDescending(t => t.CreatedAt) .Skip(textRequest.PageNumber * textRequest.PageSize) .Take(textRequest.PageSize) .ToListAsync(); var textDtos = _mapper.Map <List <TextDto> > (texts); return(textDtos); }
public async Task <IEnumerable <TextDto> > GetTextsCategoryAsync(TextResourceParameters textRequest) { var texts = await _context.Texts .Include(s => s.Sentences.OrderByDescending(o => o.Order)) .ThenInclude(w => w.Words) .Where(t => t.Category.Equals(textRequest.Category)) .Where(t => t.Status.Equals(PublishStates.Published.ToString())) .OrderByDescending(t => t.CreatedAt) .Skip(textRequest.PageNumber * textRequest.PageSize) .Take(textRequest.PageSize) .ToListAsync(); var textDtos = _mapper.Map <List <TextDto> > (texts); return(textDtos); }