public BaseResponse <BasePaginationSet <ProductCategoryViewModel> > Search(string keyword, int page = SystemParam.PAGE, int pageSize = SystemParam.PAGE_SIZE) { BaseResponse <BasePaginationSet <ProductCategoryViewModel> > response = new BaseResponse <BasePaginationSet <ProductCategoryViewModel> >(); response.ResponseCode = BaseCode.SUCCESS; var queryProductCategory = productCategoryService.GetAll().Where(x => x.IsActive); if (!string.IsNullOrEmpty(keyword)) { queryProductCategory = queryProductCategory.Where(x => x.Name.ToUpper().Contains(keyword.ToUpper()) || x.Alias.ToUpper().Contains(keyword.ToUpper()) || x.Category.Name.ToUpper().Contains(keyword.ToUpper()) || x.Category.Alias.ToUpper().Contains(keyword.ToUpper())); } IQueryable <ProductCategoryViewModel> queryResponse = queryProductCategory.Select(x => new ProductCategoryViewModel { ProductCategoryID = x.ProductCategoryID, Name = x.Name, Alias = x.Alias, IsHomeFlag = x.IsHomeFlag, IsActive = x.IsActive, Sequence = x.Sequence, CategoryID = x.CategoryID, CategoryName = x.Category.Name, SequenceCategroy = x.Category.Sequence, }).OrderBy(x => x.SequenceCategroy).ThenBy(x => x.CategoryName).ThenBy(x => x.Sequence).ThenBy(x => x.Name); int totalRow = queryResponse.Count(); List <ProductCategoryViewModel> lstResult = queryResponse.Skip((page - 1) * pageSize).Take(pageSize).ToList(); var paginationset = new BasePaginationSet <ProductCategoryViewModel>() { Items = lstResult, Page = page, PageSize = pageSize, TotalItems = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize), }; response.Data = paginationset; return(response); }
public BaseResponse <BasePaginationSet <ProductCategoryViewModel> > Search(string keyword, int page = SystemParam.PAGE, int pageSize = SystemParam.PAGE_SIZE) { BaseResponse <BasePaginationSet <ProductCategoryViewModel> > response = new BaseResponse <BasePaginationSet <ProductCategoryViewModel> >(); response.ResponseCode = BaseCode.SUCCESS; var queryCategory = categoryService.GetAll().Where(x => x.IsActive); var queryProductCategory = productCategoryService.GetAll().Where(x => x.IsActive); IQueryable <ProductCategoryViewModel> queryResponse = queryProductCategory.Join(queryCategory, pc => pc.CategoryID, c => c.CategoryID, (pc, c) => new { pc = pc, c = c }) .Select(x => new ProductCategoryViewModel { Name = x.pc.Name, CategoryID = x.pc.CategoryID, Alias = x.pc.Alias, HomeFlag = x.pc.IsHomeFlag, IsActive = x.pc.IsActive, Sequence = x.pc.Sequence, CategoryName = x.c.Name, }).OrderBy(x => x.Sequence).ThenBy(x => x.Alias); int totalRow = queryResponse.Count(); List <ProductCategoryViewModel> lstResult = queryResponse.Skip((page - 1) * pageSize).Take(pageSize).ToList(); var paginationset = new BasePaginationSet <ProductCategoryViewModel>() { Items = lstResult, Page = page, PageSize = pageSize, TotalItems = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize), }; response.Data = paginationset; return(response); }