public async Task <IActionResult> GetProductGroupfilter([FromQuery] ProductGroupDTO_Filter input) { return(Ok(await service.GetProductGroupFilter(input))); }
public async Task <ServiceResponse <List <ProductGroupDTO_ToReturn> > > SearchProductGroupPaginate(ProductGroupDTO_Filter filter) { var queryable = _dbContext.ProductGroups.Include(x => x.Product).AsQueryable(); //filter if (!String.IsNullOrWhiteSpace(filter.Name)) { queryable = queryable.Where(x => (x.Name).Contains(filter.Name)); } if (!String.IsNullOrWhiteSpace(filter.GroupCode)) { queryable = queryable.Where(x => (x.GroupCode).Contains(filter.GroupCode)); } //Order By if (!string.IsNullOrWhiteSpace(filter.OrderingField)) { try { queryable = queryable.OrderBy($"{filter.OrderingField} {(filter.AscendingOrder ? "ascending" : "descending")}"); } catch { return(ResponseResultWithPagination.Failure <List <ProductGroupDTO_ToReturn> >($"Could not order by field: {filter.OrderingField}")); } } //Add Paginate var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(queryable, filter.RecordsPerPage, filter.Page); //Excute query var productGroup = await queryable.Paginate(filter).ToListAsync(); var result = _mapper.Map <List <ProductGroupDTO_ToReturn> >(productGroup); return(ResponseResultWithPagination.Success(result, paginationResult)); }
public async Task <ServiceResponseWithPagination <List <ProductGroupDTO_ToReturn> > > GetProductGroupFilter(ProductGroupDTO_Filter input) { var queryable = _context.ProductGroups.AsQueryable(); //Filter if (!string.IsNullOrWhiteSpace(input.Name)) { queryable = queryable.Where(x => x.Name.Contains(input.Name)); } //Ordering if (!string.IsNullOrWhiteSpace(input.OrderingField)) { try { queryable = queryable.OrderBy($"{input.OrderingField} {(input.AscendingOrder ? "asc" : "desc")}"); } catch (System.Exception ex) { _logger.LogError(ex.Message); return(ResponseResultWithPagination.Failure <List <ProductGroupDTO_ToReturn> >(ex.Message)); } } var paginationResult = await _httpContext.HttpContext.InsertPaginationParametersInResponse(queryable, input.RecordsPerPage, input.Page); var data = await queryable.Paginate(input).ToListAsync(); var dto = _mapper.Map <List <ProductGroupDTO_ToReturn> >(data); return(ResponseResultWithPagination.Success(dto, paginationResult)); }
public async Task <IActionResult> SearchProductGroupPaginate([FromQuery] ProductGroupDTO_Filter filter) { var result = await _productGroup.SearchProductGroupPaginate(filter); return(Ok(result)); }