コード例 #1
0
        public async Task <ActionResult <GetListResponse <WatchDto> > > GetWatchesAsync(
            [FromQuery] string title      = null,
            [FromQuery] Gender?gender     = null,
            [FromQuery] string brandTitle = null,
            [FromQuery] int pageNumber    = 0,
            [FromQuery] int?pageSize      = null)
        {
            if (pageSize == null)
            {
                pageSize = _config.ApiDefaultPageSize;
            }

            PagingValidationHelper.ValidatePageNumber(pageNumber);
            PagingValidationHelper.ValidatePageSize((int)pageSize, _config.ApiPageSizeLimit);

            var watchesPage = await _watchRepository.GetWatchesAsync(title, gender, brandTitle, pageNumber, (int)pageSize);

            return(new GetListResponse <WatchDto>
            {
                PageNumber = watchesPage.PageNumber,
                PageSize = watchesPage.PageSize,
                Total = watchesPage.Total,
                Count = watchesPage.Count,
                Results = watchesPage.Results.Select(watch => watch.ToWatchDto()).ToList()
            });
        }
コード例 #2
0
        public async Task <ActionResult <GetListResponse <BrandDto> > > GetBrandsAsync(
            [FromQuery] int pageNumber = 0,
            [FromQuery] int?pageSize   = null)
        {
            if (pageSize == null)
            {
                pageSize = _config.ApiDefaultPageSize;
            }

            PagingValidationHelper.ValidatePageNumber(pageNumber);
            PagingValidationHelper.ValidatePageSize((int)pageSize, _config.ApiPageSizeLimit);

            var brandsPage = await _brandRepository.GetBrandsAsync(pageNumber, (int)pageSize);

            return(new GetListResponse <BrandDto>
            {
                PageNumber = brandsPage.PageNumber,
                PageSize = brandsPage.PageSize,
                Total = brandsPage.Total,
                Count = brandsPage.Count,
                Results = brandsPage.Results.Select(brand => brand.ToBrandDto()).ToList()
            });
        }