public IEnumerable <ProductDto> SearchedRows(ProductResourceParameter productResourceParameter) { var Rep_Product = _iProductRepository.SearchedRows(productResourceParameter); var productToReturn = _mapper.Map <IEnumerable <ProductDto> >(Rep_Product); return(productToReturn); }
private string CreateProductResourceUri(ProductResourceParameter productResourceParameter, ResourceUriType type) { switch (type) { case ResourceUriType.PreviousPage: return(_urlHelper.Link("GetProducts", new { SearchQuery = productResourceParameter.SearchQuery, name = productResourceParameter.Name, pageNumber = productResourceParameter.pageNumber - 1, pageSize = productResourceParameter.PageSize })); case ResourceUriType.NextPage: return(_urlHelper.Link("GetProducts", new { SearchQuery = productResourceParameter.SearchQuery, name = productResourceParameter.Name, pageNumber = productResourceParameter.pageNumber + 1, pageSize = productResourceParameter.PageSize })); default: return(_urlHelper.Link("GetProducts", new { SearchQuery = productResourceParameter.SearchQuery, name = productResourceParameter.Name, pageNumber = productResourceParameter.pageNumber, pageSize = productResourceParameter.PageSize })); } }
public IEnumerable <ProductDto> SearchedRows(ProductResourceParameter productResourceParameter) { var products = _iProductRepository.SearchedRows(productResourceParameter); var productDtos = _mapper.Map <IEnumerable <ProductDto> >(products); return(productDtos); }
public async Task <IEnumerable <ProductDto> > SearchedRowsAsync(ProductResourceParameter productResourceParameter) { var products = await _iProductRepository.SearchedRowsAsync(productResourceParameter); var productDtos = _mapper.Map <IEnumerable <ProductDto> >(products); return(productDtos); }
public ActionResult GetProducts([FromQuery] ProductResourceParameter productResourceParameter) { if (productResourceParameter == null) { var AllProducts = _ProductService.AllRows(); return(new JsonResult(AllProducts)); } else { var AllProducts = _ProductService.SearchedRows(productResourceParameter); return(Ok(AllProducts)); } }
public async Task <ActionResult> GetProducts([FromQuery] ProductResourceParameter productResourceParameter) { IEnumerable <ProductDto> ProductDtos; if (productResourceParameter == null) { ProductDtos = await _ProductService.GetAllAsync(); } else { ProductDtos = await _ProductService.SearchedRowsAsync(productResourceParameter); } return(new JsonResult(ProductDtos)); }
public ActionResult GetProducts([FromQuery] ProductResourceParameter productResourceParameter) { IEnumerable <ProductDto> ProductDtos; if (productResourceParameter == null) { ProductDtos = _ProductService.GetAll(); } else { ProductDtos = _ProductService.SearchedRows(productResourceParameter); } return(Ok(ProductDtos)); }
public PagedList <Product> GetProducts(ProductResourceParameter productResourceParameter) { var collectionBeforePaging = _context.Product.OrderBy(x => x.Name).AsQueryable(); if (!string.IsNullOrWhiteSpace(productResourceParameter.Name)) { var nameForWhereClause = productResourceParameter.Name.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(x => x.Name.ToLowerInvariant() == nameForWhereClause); } if (!string.IsNullOrWhiteSpace(productResourceParameter.SearchQuery)) { var searchQueryWhereCaluse = productResourceParameter.SearchQuery.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(x => x.Name.ToLowerInvariant().Contains(searchQueryWhereCaluse) || x.Price.Contains(searchQueryWhereCaluse)); } return(PagedList <Product> .Create(collectionBeforePaging, productResourceParameter.pageNumber, productResourceParameter.PageSize)); }
public IActionResult GetProducts([FromQuery] ProductResourceParameter productResourceParameter) { var products = _productCoreAPIRepository.GetProducts(productResourceParameter); var prevPageLink = products.HasPrevious ? CreateProductResourceUri(productResourceParameter, ResourceUriType.PreviousPage) : null; var nextPageLink = products.HasNext ? CreateProductResourceUri(productResourceParameter, ResourceUriType.NextPage) : null; var paginationMetadata = new { totalCount = products.TotalCount, pageSize = products.PageSize, currentPage = products.CurrentPage, totalPages = products.TotalPages, previousPageLink = prevPageLink, nextPageLink = nextPageLink }; Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata)); return(Ok(products)); }
public IEnumerable <Product> SearchedRows(ProductResourceParameter parameter) { string searchQuery = parameter.SearchQuery; IQueryable <Product> Products = _context.Products; if (!(parameter.InventoryItemId == 0)) { Products = Products.Where(a => (a.InventoryItemId == parameter.InventoryItemId)); } if (!string.IsNullOrWhiteSpace(searchQuery)) { Products = Products.Where(a => a.Name.Contains(searchQuery) || a.SKU.Contains(searchQuery) ); } return(Products.ToList()); }
public async Task <IEnumerable <Product> > SearchedRowsAsync(ProductResourceParameter parameter) { string searchQuery = parameter.SearchQuery; var productTask = Task.Run(() => _context.Products); IQueryable <Product> Products = await productTask; if (!(parameter.InventoryItemId == 0)) { Products = await Task.Run(() => Products.Where(a => (a.InventoryItemId == parameter.InventoryItemId))); } if (!string.IsNullOrWhiteSpace(searchQuery)) { Products = await Task.Run(() => Products.Where(a => a.Name.Contains(searchQuery) || a.Description.Contains(searchQuery) || (a.CurrentPrice.ToString() == searchQuery) || a.SKU.Contains(searchQuery))); } return(await Products.ToListAsync()); }