public async Task <IActionResult> Get(int pageSize = 50, int pageNo = 1) { // Validate paging parameters if (pageSize <= 0 || pageNo <= 0) { return(BadRequest()); } // Limit max pageSize if (pageSize > 200) { return(BadRequest()); } var shortUrls = await _shortUrlRepository.FindAll(pageSize, pageNo - 1); var count = await _shortUrlRepository.Count(); var shortUrlDtos = _mapper.Map <IList <ShortUrlDto> >(shortUrls); var response = new PageDto <ShortUrlDto> { PageCount = (int)Math.Ceiling((decimal)count / pageSize), PageNo = pageNo, Data = shortUrlDtos }; return(Ok(response)); }
private async Task <long> GetTotalCount(CancellationToken cancellationToken = default(CancellationToken)) { return(CurrentUser.IsAdmin() ? await _shortUrlRepository.Count(cancellationToken) : await _shortUrlRepository.GetCountByUser(CurrentUser.Id, cancellationToken)); }