private string CreateProductsResourceUri(CollectionResourceParameters logResourceParameters, ResourceUriType type) { switch (type) { case ResourceUriType.PreviousPage: return(_urlHelper.Link("GetLogs", new { searchQuery = logResourceParameters.SearchQuery, pageNumber = logResourceParameters.PageNumber - 1, pageSize = logResourceParameters.PageSize })); case ResourceUriType.NextPage: return(_urlHelper.Link("GetLogs", new { searchQuery = logResourceParameters.SearchQuery, pageNumber = logResourceParameters.PageNumber + 1, pageSize = logResourceParameters.PageSize })); case ResourceUriType.Current: default: return(_urlHelper.Link("GetLogs", new { searchQuery = logResourceParameters.SearchQuery, pageNumber = logResourceParameters.PageNumber, pageSize = logResourceParameters.PageSize })); } }
public IActionResult Get(CollectionResourceParameters vendorResourceParameters) { var vendorsFromRepo = _vendorsRepository.GetVendors(vendorResourceParameters); var vendors = Mapper.Map <IEnumerable <VendorDto> >(vendorsFromRepo); var previousPageLink = vendorsFromRepo.HasPrevious ? CreateVendorsResourceUri(vendorResourceParameters, ResourceUriType.PreviousPage) : null; var nextPageLink = vendorsFromRepo.HasNext ? CreateVendorsResourceUri(vendorResourceParameters, ResourceUriType.NextPage) : null; var paginationMetadata = new { previousPageLink = previousPageLink, nextPageLink = nextPageLink, totalCount = vendorsFromRepo.TotalCount, pageSize = vendorsFromRepo.PageSize, currentPage = vendorsFromRepo.CurrentPage, totalPages = vendorsFromRepo.TotalPages }; Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata)); return(Ok(vendors)); }
public PagedList <Log> Get(CollectionResourceParameters logResourceParameters, int?logLevel = null) { IQueryable <Log> collectionBeforePaging = _context.Logs.OrderByDescending(o => o.CreatedWhen); if (logLevel != null) { collectionBeforePaging = collectionBeforePaging.Where(x => x.EvenType == ((LogLevelEnum)Enum.ToObject(typeof(LogLevelEnum), logLevel)).GetStringValue()); } if (!string.IsNullOrEmpty(logResourceParameters.SearchQuery)) { // trim & ignore casing var searchQueryForWhereClause = logResourceParameters.SearchQuery.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.EvenType.ToLowerInvariant().Contains(searchQueryForWhereClause) || a.Message.ToLowerInvariant().Contains(searchQueryForWhereClause) || a.CreatedWhen.ToLocalTime().ToString(CultureInfo.CurrentCulture).ToLowerInvariant().Contains(searchQueryForWhereClause)); } return(PagedList <Log> .Create(collectionBeforePaging, logResourceParameters.PageNumber, logResourceParameters.PageSize)); }
public PagedList <Vendor> GetVendors(CollectionResourceParameters resourceParameters) { IQueryable <Vendor> collectionBeforePaging = _context.Vendors.Include(x => x.Contact).ApplySort(resourceParameters.OrderBy, _propertyMappingService.GetPropertyMapping <VendorDto, Vendor>()); if (!string.IsNullOrEmpty(resourceParameters.SearchQuery)) { // trim & ignore casing var searchQueryForWhereClause = resourceParameters.SearchQuery.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.Name.ToLowerInvariant().Contains(searchQueryForWhereClause) || a.Dic.ToLowerInvariant().Contains(searchQueryForWhereClause) || a.Ico.ToString().ToLowerInvariant().Contains(searchQueryForWhereClause) || a.Director.ToLowerInvariant().Contains(searchQueryForWhereClause)) .Where(c => c.Contact != null && (c.Contact.Address1.ToLowerInvariant().Contains(searchQueryForWhereClause) || c.Contact.Address2.ToLowerInvariant().Contains(searchQueryForWhereClause) || c.Contact.City.ToLowerInvariant().Contains(searchQueryForWhereClause) || c.Contact.Psc.ToString().ToLowerInvariant().Contains(searchQueryForWhereClause) || c.Contact.State.ToLowerInvariant().Contains(searchQueryForWhereClause))); } return(PagedList <Vendor> .Create(collectionBeforePaging, resourceParameters.PageNumber, resourceParameters.PageSize)); }
private string CreateProductsResourceUri(CollectionResourceParameters productResourceParameters, ResourceUriType type) { switch (type) { case ResourceUriType.PreviousPage: return(_urlHelper.Link("GetCatalogItems", new { fields = productResourceParameters.Fields, orderBy = productResourceParameters.OrderBy, searchQuery = productResourceParameters.SearchQuery, pageNumber = productResourceParameters.PageNumber - 1, pageSize = productResourceParameters.PageSize })); case ResourceUriType.NextPage: return(_urlHelper.Link("GetCatalogItems", new { fields = productResourceParameters.Fields, orderBy = productResourceParameters.OrderBy, searchQuery = productResourceParameters.SearchQuery, pageNumber = productResourceParameters.PageNumber + 1, pageSize = productResourceParameters.PageSize })); case ResourceUriType.Current: default: return(_urlHelper.Link("GetCatalogItems", new { fields = productResourceParameters.Fields, orderBy = productResourceParameters.OrderBy, searchQuery = productResourceParameters.SearchQuery, pageNumber = productResourceParameters.PageNumber, pageSize = productResourceParameters.PageSize })); } }
public IActionResult Get(Guid categoryId, CollectionResourceParameters productResourceParameters) { var productsFromRepo = _productsRepository.GetProducts(productResourceParameters, categoryId); var products = Mapper.Map <IEnumerable <ProductDto> >(productsFromRepo); var previousPageLink = productsFromRepo.HasPrevious ? CreateProductsResourceUri(productResourceParameters, ResourceUriType.PreviousPage) : null; var nextPageLink = productsFromRepo.HasNext ? CreateProductsResourceUri(productResourceParameters, ResourceUriType.NextPage) : null; var paginationMetadata = new { previousPageLink = previousPageLink, nextPageLink = nextPageLink, totalCount = productsFromRepo.TotalCount, pageSize = productsFromRepo.PageSize, currentPage = productsFromRepo.CurrentPage, totalPages = productsFromRepo.TotalPages }; Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata)); return(Ok(products)); }
public PagedList <User> GetUsers(CollectionResourceParameters userResourceParameters) { IQueryable <User> collectionBeforePaging = _context.Users.Include(x => x.Contact) .ApplySort(userResourceParameters.OrderBy, _propertyMappingService.GetPropertyMapping <UserDto, User>()); if (!string.IsNullOrEmpty(userResourceParameters.SearchQuery)) { // trim & ignore casing var searchQueryForWhereClause = userResourceParameters.SearchQuery.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.Username.ToLowerInvariant().Contains(searchQueryForWhereClause) || a.Firstname.ToLowerInvariant().Contains(searchQueryForWhereClause) || a.Lastname.ToLowerInvariant().Contains(searchQueryForWhereClause) || a.Email.ToLowerInvariant().Contains(searchQueryForWhereClause)) .Where(c => c.Contact != null && (c.Contact.Address1.ToLowerInvariant().Contains(searchQueryForWhereClause) || c.Contact.Address2.ToLowerInvariant().Contains(searchQueryForWhereClause) || c.Contact.City.ToLowerInvariant().Contains(searchQueryForWhereClause) || c.Contact.Psc.ToString().ToLowerInvariant().Contains(searchQueryForWhereClause) || c.Contact.State.ToLowerInvariant().Contains(searchQueryForWhereClause))); } return(PagedList <User> .Create(collectionBeforePaging, userResourceParameters.PageNumber, userResourceParameters.PageSize)); }
/// <summary> /// Gets collection of products by ProductResourceParameters /// </summary> /// <param name="productResourceParameters"></param> /// <param name="categoryId"></param> /// <returns></returns> public PagedList <Product> GetProducts(CollectionResourceParameters productResourceParameters, Guid?categoryId = null) { IQueryable <Product> collectionBeforePaging = _context.Products.Include(x => x.Category) .Include(x => x.ProductState).Include(x => x.Vendor) .ApplySort(productResourceParameters.OrderBy, _propertyMappingService.GetPropertyMapping <ProductDto, Product>()); if (categoryId != null) { collectionBeforePaging = collectionBeforePaging.Where(x => x.CategoryId == categoryId); } if (!string.IsNullOrEmpty(productResourceParameters.SearchQuery)) { // trim & ignore casing var searchQueryForWhereClause = productResourceParameters.SearchQuery.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.Name.ToLowerInvariant().Contains(searchQueryForWhereClause) || a.Category.Name.ToLowerInvariant().Contains(searchQueryForWhereClause) || a.Description.ToLowerInvariant().Contains(searchQueryForWhereClause)); } return(PagedList <Product> .Create(collectionBeforePaging, productResourceParameters.PageNumber, productResourceParameters.PageSize)); }
public PagedList <Category> GetCategories(CollectionResourceParameters categoriesResourceParameters) { throw new NotImplementedException(); }