public async Task <ProductsPageViewModel> FindProductsAsync(string sku, int pageIndex, int pageSize) { pageSize = pageSize == 0 ? _settings.DefaultPageSize : pageSize; PaginatedList <Product> products = await PaginatedList <Product> .FromIQueryable(_productsRepository.FindProductsAsync(sku), pageIndex, pageSize); if (products.Count() == 1) { //only one record found Product product = products.Single(); string productId = product.ProductId.ToString(); //cache a product if not in cache yet if (!await _productCacheRepository.IsValueCachedAsync(productId)) { await _productCacheRepository.SetValueAsync(productId, product); } //prepare prices if (!await _pricesCacheRepository.IsValueCachedAsync(productId)) { //prepare prices beforehand ThreadPool.QueueUserWorkItem(delegate { CallPreparePricesApiAsync(productId); }); } } ; return(new ProductsPageViewModel(products)); }
public async Task <ProductsPageViewModel> GetAllProductsAsync(int pageIndex, int pageSize) { pageSize = pageSize == 0 ? _settings.DefaultPageSize : pageSize; PaginatedList <Product> products = await PaginatedList <Product> .FromIQueryable(_productsRepository.GetAllProductsAsync(), pageIndex, pageSize); return(new ProductsPageViewModel(products)); }
/// <summary> /// Obtaines a filtered and paginated list of services /// </summary> /// <param name="userId">User id (to define activated services)</param> /// <param name="getServicesListDto">Model for getting the list with filtering and paging</param> /// <returns>Returns the filtered and paginated list of services</returns> public async Task <ServiceListDto> GetAllServicesAsync(Guid userId, GetServicesListDto getServicesListDto) { var services = await PaginatedList <Service> .FromIQueryable(_servicesRepository.GetAllServicesAsync(userId, getServicesListDto.Filter), getServicesListDto.CurrentPage, getServicesListDto.PageSize == 0?_settings.PageSize : getServicesListDto.PageSize); var serviceListDto = new ServiceListDto(services, _mapper); return(serviceListDto); }
private async Task <TestModelListDto> GetAllItemsFilteredAsync(GetPaginatedListDto getPaginatedListDto) { var testModels = await PaginatedList <TestModel> .FromIQueryable(GetAllItemsAsync(getPaginatedListDto.Filter), getPaginatedListDto.CurrentPage, getPaginatedListDto.PageSize == 0?_settings.Value.PageSize : getPaginatedListDto.PageSize); var testModelListDto = new TestModelListDto(testModels); return(testModelListDto); }