public async Task <ActionResult <ImagesPageDto> > GetImagesPage([FromQuery] int?pageSize, [FromQuery] int?pageNo)
        {
            try
            {
                pageSize ??= 20;
                pageNo ??= 1;
                var count = await _imagesService.GetImagesCount();

                pageSize = pageSize > 100 ? 100 : pageSize;

                var pagesInfo = PagesInfo.GetPagesInfo(count, pageNo.Value, pageSize.Value);
                var images    = await _imagesService.FetchImageSet(pagesInfo.StartIndex, pagesInfo.PageSize);

                var dto = new ImagesPageDto
                {
                    PagesInfo = pagesInfo,
                    Images    = images.Select(i => new ImageListItemDto
                    {
                        Id              = i.Id,
                        Name            = i.Name,
                        Width           = i.Width,
                        Height          = i.Height,
                        SizeKb          = i.GetSizeKbString(),
                        Base64Thumbnail = i.GetBase64Thumbnail()
                    }).ToList()
                };

                return(Ok(dto));
            }
            catch (ArgumentException exc)
            {
                return(BadRequest(exc.Message));
            }
        }
Exemple #2
0
        public async Task OnGetAsync(int?pageNo)
        {
            var imagesCount = await _imagesService.GetImagesCount();

            Pager  = PagesInfo.GetPagesInfo(imagesCount, pageNo ?? 1, _pageSize);
            Images = await _imagesService.FetchImageSet(Pager.StartIndex, Pager.PageSize);
        }