Beispiel #1
0
        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));
        }