/// <summary> /// Get Discount Types /// </summary> public DiscountTypeSearchRequestResponse Get([FromUri] DiscountTypeSearchRequest request) { if (request == null || !ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } return(discountTypeService.SearchDiscountType(request).CreateFrom()); }
/// <summary> /// Search Discount Type /// </summary> public DiscountTypeSearchRequestResponse SearchDiscountType(DiscountTypeSearchRequest request) { int rowCount; return(new DiscountTypeSearchRequestResponse { DiscountTypes = discountTypeRepository.SearchDiscountType(request, out rowCount), TotalCount = rowCount }); }
/// <summary> /// Search Discount Type /// </summary> public IEnumerable <DiscountType> SearchDiscountType(DiscountTypeSearchRequest request, out int rowCount) { int fromRow = (request.PageNo - 1) * request.PageSize; int toRow = request.PageSize; Expression <Func <DiscountType, bool> > query = discountType => (string.IsNullOrEmpty(request.DiscountTypeFilterText) || (discountType.DiscountTypeCode.Contains(request.DiscountTypeFilterText)) || (discountType.DiscountTypeName.Contains(request.DiscountTypeFilterText))); rowCount = DbSet.Count(query); return(request.IsAsc ? DbSet.Where(query) .OrderBy(discountTypeByClause[request.DiscountTypeOrderBy]) .Skip(fromRow) .Take(toRow) .ToList() : DbSet.Where(query) .OrderByDescending(discountTypeByClause[request.DiscountTypeOrderBy]) .Skip(fromRow) .Take(toRow) .ToList()); }