public IActionResult GetThietBis(ThietBisResourceParameters thietBisResourceParameters) { var thietBisFromRepo = _thucLucRepository.GetThietBis(thietBisResourceParameters); var previousPageLink = thietBisFromRepo.HasPrevious ? CreateThietBisResourceUri(thietBisResourceParameters, ResourceUriType.PreviousPage) : null; var nextPageLink = thietBisFromRepo.HasNext ? CreateThietBisResourceUri(thietBisResourceParameters, ResourceUriType.NextPage) : null; var paginationMetadata = new { totalCount = thietBisFromRepo.TotalCount, pageSize = thietBisFromRepo.PageSize, currentPage = thietBisFromRepo.CurrentPage, totalPages = thietBisFromRepo.TotalPages, previousPageLink = previousPageLink, nextPageLink = nextPageLink }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(paginationMetadata)); var thietbis = Mapper.Map <IEnumerable <ThietBiDto> >(thietBisFromRepo); return(Ok(thietbis)); }
private string CreateThietBisResourceUri(ThietBisResourceParameters thietBisResourceParameters, ResourceUriType type) { switch (type) { case ResourceUriType.PreviousPage: return(_urlHelper.Link("GetThietBis", new { pageNumber = thietBisResourceParameters.PageNumber - 1, pageSize = thietBisResourceParameters.PageSize, search = thietBisResourceParameters.Search, nhom = thietBisResourceParameters.Nhom, chungLoai = thietBisResourceParameters.ChungLoai, loai = thietBisResourceParameters.Loai, hangSanXuat = thietBisResourceParameters.HangSanXuat, khuVuc = thietBisResourceParameters.KhuVuc, dvQuanLy = thietBisResourceParameters.DvQuanLy, dvSoHuu = thietBisResourceParameters.DvSoHuu })); case ResourceUriType.NextPage: return(_urlHelper.Link("GetThietBis", new { pageNumber = thietBisResourceParameters.PageNumber + 1, pageSize = thietBisResourceParameters.PageSize, search = thietBisResourceParameters.Search, nhom = thietBisResourceParameters.Nhom, chungLoai = thietBisResourceParameters.ChungLoai, loai = thietBisResourceParameters.Loai, hangSanXuat = thietBisResourceParameters.HangSanXuat, khuVuc = thietBisResourceParameters.KhuVuc, dvQuanLy = thietBisResourceParameters.DvQuanLy, dvSoHuu = thietBisResourceParameters.DvSoHuu })); default: return(_urlHelper.Link("GetThietBis", new { pageNumber = thietBisResourceParameters.PageNumber, pageSize = thietBisResourceParameters.PageSize, search = thietBisResourceParameters.Search, nhom = thietBisResourceParameters.Nhom, chungLoai = thietBisResourceParameters.ChungLoai, loai = thietBisResourceParameters.Loai, hangSanXuat = thietBisResourceParameters.HangSanXuat, khuVuc = thietBisResourceParameters.KhuVuc, dvQuanLy = thietBisResourceParameters.DvQuanLy, dvSoHuu = thietBisResourceParameters.DvSoHuu })); } }
public PagedList <ThietBi> GetThietBis(ThietBisResourceParameters thietBisResourceParameters) { var collectionBeforePaging = _context.ThietBis .OrderBy(a => a.MaThietBi) .AsQueryable(); if (!string.IsNullOrEmpty(thietBisResourceParameters.Nhom)) { var nhomForWhereClause = thietBisResourceParameters.Nhom.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.Nhom.ToLowerInvariant() == nhomForWhereClause); } if (!string.IsNullOrEmpty(thietBisResourceParameters.ChungLoai)) { var chungLoaiForWhereClause = thietBisResourceParameters.ChungLoai.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.ChungLoai.ToLowerInvariant() == chungLoaiForWhereClause); } if (!string.IsNullOrEmpty(thietBisResourceParameters.Loai)) { var loaiForWhereClause = thietBisResourceParameters.Loai.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.Loai.ToLowerInvariant() == loaiForWhereClause); } if (!string.IsNullOrEmpty(thietBisResourceParameters.HangSanXuat)) { var hangSanXuatForWhereClause = thietBisResourceParameters.HangSanXuat.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.HangSanXuat.ToLowerInvariant() == hangSanXuatForWhereClause); } if (!string.IsNullOrEmpty(thietBisResourceParameters.KhuVuc)) { var khuVucForWhereClause = thietBisResourceParameters.KhuVuc.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.KhuVuc.ToLowerInvariant() == khuVucForWhereClause); } if (!string.IsNullOrEmpty(thietBisResourceParameters.DvQuanLy)) { var dvQuanLyForWhereClause = thietBisResourceParameters.DvQuanLy.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.DvQuanLy.ToLowerInvariant() == dvQuanLyForWhereClause); } if (!string.IsNullOrEmpty(thietBisResourceParameters.DvSoHuu)) { var dvSoHuuForWhereClause = thietBisResourceParameters.DvSoHuu.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging.Where(a => a.DvSoHuu.ToLowerInvariant() == dvSoHuuForWhereClause); } if (!string.IsNullOrEmpty(thietBisResourceParameters.Search)) { var searchForWhereClause = thietBisResourceParameters.Search.Trim().ToLowerInvariant(); collectionBeforePaging = collectionBeforePaging .Where(a => a.MaThietBi.ToLowerInvariant().Contains(searchForWhereClause)); } return(PagedList <ThietBi> .Create(collectionBeforePaging, thietBisResourceParameters.PageNumber, thietBisResourceParameters.PageSize)); }