public async Task <IEnumerable <ProductDto> > GetPaginatedProductsByDeclination(string declination, int pageIndex, int pageSize)
        {
            (IEnumerable <Models.Product> products, int count) = await iProductFetcher.GetPaginatedProductsByDeclination(declination, pageIndex, pageSize);

            Response.Headers.Add(TOTAL_COUNT_HEADER, count.ToString());

            return(iMapper.Map <IEnumerable <ProductDto> >(products));
        }
Beispiel #2
0
        public override async Task <PaginedProductItemsResponse?> GetPaginedProductsByDeclination(PaginedProductItemsRequest request, ServerCallContext context)
        {
            if (string.IsNullOrWhiteSpace(request.Declination))
            {
                context.Status = new Status(StatusCode.InvalidArgument, $"Arguments are invalid, declination can't be null or empty");
                return(null);
            }

            try
            {
                (IEnumerable <Models.Product> products, int count) = await iProductFetcher.GetPaginatedProductsByDeclination(request.Declination, request.PageIndex, request.PageSize);

                return(BuildPaginedResponse(products, count, request));
            }
            catch (Exception exception)
            {
                context.Status = new Status(StatusCode.Internal, exception.Message);
                return(null);
            }
        }