public HttpResponseMessage GetAll(HttpRequestMessage request, int page, int pageSize = 20) { return(CreateHttpResponse(request, () => { int totalRow = 0; var model = _districtService.GetAll(); totalRow = model.Count(); var query = model.OrderBy(x => x.ID).Skip(page * pageSize).Take(pageSize); var responseData = Mapper.Map <IEnumerable <District>, IEnumerable <DistrictViewModel> >(query); foreach (var item in responseData) { var listPO = _poService.GetAllPOByDistrictId(item.ID); item.NoPO = listPO.Count(); } //ban test lai thu var paginationSet = new PaginationSet <DistrictViewModel>//sai ne ban. { Items = responseData, Page = page, TotalCount = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize) }; var response = request.CreateResponse(HttpStatusCode.OK, paginationSet); return response; })); }
public HttpResponseMessage GetByDistrictId(HttpRequestMessage request, int id) { return(CreateHttpResponse(request, () => { var model = _poService.GetAllPOByDistrictId(id); var responseData = Mapper.Map <IEnumerable <PO>, IEnumerable <POViewModel> >(model); var response = request.CreateResponse(HttpStatusCode.OK, responseData); return response; })); }