/// <summary> /// Get all invoice with pagging /// </summary> /// <param name="page">Current page</param> /// <param name="pageSize">Page size</param> /// <returns></returns> public ApiResponseViewModel GetAllWithPagging(int?page, int pageSize) { var result = new List <InvoiceViewModel>(); var paginationSet = new PaginationSet <InvoiceViewModel>(); var response = new ApiResponseViewModel { Code = CommonConstants.ApiResponseSuccessCode, Message = null, Result = null }; try { var currentPage = page ?? 1; int totalRow = 0; var query = _InvoiceRepository.GetMulti(m => m.IsActive == true); totalRow = query.Count(); result = query.OrderBy(x => x.ID).Skip((currentPage - 1) * pageSize) .Take(pageSize) .Select(m => new InvoiceViewModel { ID = m.ID, InvoiceCode = m.InvoiceCode, CreatedDate = m.CreatedDate != null ? m.CreatedDate : DateTime.Now, CustomerID = m.CustomerID, InOut = m.InOut, Status = m.Status, IsActive = m.IsActive ?? false, Value = m.Value, InvoiceDetails = _InvoiceDetailRepository.GetListInvoiceDetailsByInvoiceID(m.ID) }) .ToList(); paginationSet = new PaginationSet <InvoiceViewModel>() { Items = result, Page = currentPage, TotalCount = result.Count(), TotalPages = (int)Math.Ceiling((decimal)totalRow / pageSize) }; response.Result = paginationSet; } catch (Exception ex) { response.Code = CommonConstants.ApiResponseExceptionCode; response.Message = CommonConstants.ErrorMessage + " " + ex.Message; } return(response); }