Пример #1
0
        public ProductsResponseDto Get(ProductsDto request)
        {
            var pageSize = 5;
            var page = request.Page;
            if(page < 0) page = 0;

            var productsList = Repository.PagedProducts(page, pageSize);

            var productsResponseDtoList = productsList.ConvertAll(a => a.TranslateTo<ProductResponseDto>());

            //var products = Db.Select<Product>
            //    (a =>
            //        a.OrderByDescending(b => b.Id)
            //        .Limit(pageSize * request.Page, pageSize)
            //    )
            //    .ConvertAll(a => a.TranslateTo<ProductResponseDto>());

            var response = new ProductsResponseDto
            {
                Products = productsResponseDtoList,
                Page = page,
                PageSize = pageSize
            };

            return response;
        }
Пример #2
0
        public ProductsResponseDto Get(ProductsDto request)
        {
            var pageSize = 5;
            var page     = request.Page;

            if (page < 0)
            {
                page = 0;
            }

            var productsList = Repository.PagedProducts(page, pageSize);

            var productsResponseDtoList = productsList.ConvertAll(a => a.TranslateTo <ProductResponseDto>());

            //var products = Db.Select<Product>
            //    (a =>
            //        a.OrderByDescending(b => b.Id)
            //        .Limit(pageSize * request.Page, pageSize)
            //    )
            //    .ConvertAll(a => a.TranslateTo<ProductResponseDto>());

            var response = new ProductsResponseDto
            {
                Products = productsResponseDtoList,
                Page     = page,
                PageSize = pageSize
            };

            return(response);
        }
        public async Task <IActionResult> GetAllProductsAsync()
        {
            var items = await _productsRepository.FetchAllAsync();

            var dto = new ProductsResponseDto(_mapper.Map <List <ProductResponseDto> >(items));

            return(Ok(dto));
        }
Пример #4
0
        public async Task<ProductsResponseDto> GetAsync()
        {
            //
            var ppResponse = await Task.Factory
                .StartNew<ProductsSearchResponseDto>(callProductsProcessor);

            var productsResponse = await Task.Factory
                .StartNew<List<ProductResponseDto>>(() => getProducts(ppResponse));

            var response = new ProductsResponseDto
            {                
                Products = productsResponse
            };

            return response;
        }
Пример #5
0
        public async Task <ProductsResponseDto> GetAsync()
        {
            //
            var ppResponse = await Task.Factory
                             .StartNew <ProductsSearchResponseDto>(callProductsProcessor);

            var productsResponse = await Task.Factory
                                   .StartNew <List <ProductResponseDto> >(() => getProducts(ppResponse));

            var response = new ProductsResponseDto
            {
                Products = productsResponse
            };

            return(response);
        }
        public async Task <QueryResponseDto <ProductsResponseDto> > SearchByName(string name)
        {
            try
            {
                var products = await _mediator.Send(new SearchProductByNameQuery(name));

                var response = new ProductsResponseDto()
                {
                    Items = products.ProjectTo <ProductResponseDto>(_mapper.ConfigurationProvider)
                };

                return(QueryResponseDto <ProductsResponseDto> .Success(response));
            }
            catch (Exception ex)
            {
                return(QueryResponseDto <ProductsResponseDto> .Fail(GetErrorMessage(ex)));
            }
        }