public HttpResponseMessage GetAll(HttpRequestMessage request, string keyword, int page, int pageSize = 100) { return(CreateHttpResponse(request, () => { int totalRow = 0; var model = _serviceService.Getall(keyword); totalRow = model.Count(); var query = model.OrderBy(x => x.Name).Skip(page * pageSize).Take(pageSize); var responseData = Mapper.Map <IEnumerable <PostOffice.Model.Models.Service>, IEnumerable <ServiceViewModel> >(query); foreach (var item in responseData) { var sv = _serviceGroupService.GetById(item.GroupID); item.GroupName = sv.Name; } var paginationSet = new PaginationSet <ServiceViewModel> { Items = responseData, Page = page, TotalCount = totalRow, TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize) }; var response = request.CreateResponse(HttpStatusCode.OK, paginationSet); return response; })); }
public HttpResponseMessage GetById(HttpRequestMessage request, int id) { return(CreateHttpResponse(request, () => { var model = _serviceGroupService.GetById(id); var responseData = Mapper.Map <ServiceGroup, ServiceGroupViewModel>(model); var response = request.CreateResponse(HttpStatusCode.OK, responseData); return response; })); }