public async Task <ServiceResponseWithPagination <List <mProductGroup> > > GetProductGroupWithFilter(GetProductGroupFilterDto ProductGroupFilter) { var Queryable = _dbContext.ProductGroups .Include(x => x.Products) .AsQueryable(); if (!string.IsNullOrWhiteSpace(ProductGroupFilter.Name)) { Queryable = Queryable.Where(x => x.Name.Contains(ProductGroupFilter.Name)); } if (!string.IsNullOrWhiteSpace(ProductGroupFilter.CreateBy)) { Queryable = Queryable.Where(x => x.CreateBy.Contains(ProductGroupFilter.CreateBy)); } if (ProductGroupFilter.Status != null) { Queryable = Queryable.Where(x => x.Status == ProductGroupFilter.Status); } if (!string.IsNullOrWhiteSpace(ProductGroupFilter.OrderingField)) { try { Queryable = Queryable.OrderBy($"{ProductGroupFilter.OrderingField} {(ProductGroupFilter.AscendingOrder ? "ascending" : "descending")}"); } catch { return(ResponseResultWithPagination.Failure <List <Models.Product.ProductGroup> >($"Could not order by field: {ProductGroupFilter.OrderingField}")); } ; } var paginationResult = await _httpcontext.HttpContext.InsertPaginationParametersInResponse(Queryable, ProductGroupFilter.RecordsPerPage, ProductGroupFilter.Page); var dto = await Queryable.Paginate(ProductGroupFilter).ToListAsync(); return(ResponseResultWithPagination.Success(dto, paginationResult)); }
public async Task <IActionResult> GetProductGroupWithFilter([FromQuery] GetProductGroupFilterDto filter) { return(Ok(await _prodService.GetProductGroupWithFilter(filter))); }