public async static Task <PaginationResultDto> InsertPaginationParametersInResponse <T>(this HttpContext httpContext, IQueryable <T> queryable, int recordsPerPage, int currentPage) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } double totalAmountRecords = await queryable.CountAsync(); double totalAmountPages = Math.Ceiling(totalAmountRecords / recordsPerPage); PaginationResultDto resultDto = new PaginationResultDto() { TotalAmountRecords = totalAmountRecords, TotalAmountPages = totalAmountPages, CurrentPage = currentPage, RecordsPerPage = recordsPerPage, PageIndex = currentPage - 1 }; // httpContext.Response.Headers.Add("totalAmountRecords", totalAmountRecords.ToString()); // httpContext.Response.Headers.Add("totalAmountPages", totalAmountPages.ToString()); // httpContext.Response.Headers.Add("currentPage", currentPage.ToString()); // httpContext.Response.Headers.Add("recordsPerPage", recordsPerPage.ToString()); return(resultDto); }
public static ServiceResponseWithPagination <T> Success <T>(T data, PaginationResultDto paginationResult) { return(new ServiceResponseWithPagination <T> { Data = data, TotalAmountRecords = paginationResult.TotalAmountRecords, TotalAmountPages = paginationResult.TotalAmountPages, CurrentPage = paginationResult.CurrentPage, RecordsPerPage = paginationResult.RecordsPerPage, PageIndex = paginationResult.PageIndex }); }
public static ServiceResponseWithPagination <T> Success <T>(T data, PaginationResultDto paginationResult, string message = "") { return(new ServiceResponseWithPagination <T> { Data = data, Message = message, TotalAmountRecords = paginationResult.TotalAmountRecords, TotalAmountPages = paginationResult.TotalAmountPages, CurrentPage = paginationResult.CurrentPage, RecordsPerPage = paginationResult.RecordsPerPage }); }
public static PaginationResultDto <ContactDto> MapToPaginationResultDto(this PaginationResult <Contact> paginationResult) { var paginationDto = new PaginationResultDto <ContactDto> { TotalCount = paginationResult.RowCount }; foreach (var contact in paginationResult.Results) { paginationDto.Data.Add(MapContactToContactDto(contact)); } return(paginationDto); }