/// <summary> /// Get Service Items /// </summary> public ServiceItemSearchRequestResponse Get([FromUri] ServiceItemSearchRequest request) { if (request == null || !ModelState.IsValid) { throw new HttpException((int)HttpStatusCode.BadRequest, "Invalid Request"); } return(serviceItemService.SearchServiceItem(request).CreateFrom()); }
// <summary> // Search Service Items // </summary> public ServiceItemSearchRequestResponse SearchServiceItem(ServiceItemSearchRequest request) { int rowCount; return(new ServiceItemSearchRequestResponse { ServiceItems = serviceItemRepository.SearchServiceItems(request, out rowCount), TotalCount = rowCount }); }
/// <summary> /// Search Service Items /// </summary> public IEnumerable <ServiceItem> SearchServiceItems(ServiceItemSearchRequest request, out int rowCount) { int fromRow = (request.PageNo - 1) * request.PageSize; int toRow = request.PageSize; Expression <Func <ServiceItem, bool> > query = serviceItem => (string.IsNullOrEmpty(request.ServiceItemFilterText) || (serviceItem.ServiceItemCode.Contains(request.ServiceItemFilterText)) || (serviceItem.ServiceItemName.Contains(request.ServiceItemFilterText))) && ( (!request.ServiceTypeId.HasValue || request.ServiceTypeId == serviceItem.ServiceTypeId)); rowCount = DbSet.Count(query); return(request.IsAsc ? DbSet.Where(query) .OrderBy(serviceItemOrderByClause[request.ServiceItemOrderBy]) .Skip(fromRow) .Take(toRow) .ToList() : DbSet.Where(query) .OrderByDescending(serviceItemOrderByClause[request.ServiceItemOrderBy]) .Skip(fromRow) .Take(toRow) .ToList()); }