/// <summary> /// Map Data to Header and Details entity /// </summary> /// <param name="entities">Business Entities</param> /// <param name="detailPageNumber">Page Number</param> /// <param name="detailPageSize">Page Size</param> /// <param name="filterCount">Filter Count</param> /// <returns>Receipt Header Model</returns> public override ReceiptHeader Map(List <IBusinessEntity> entities, int?detailPageNumber = null, int?detailPageSize = null, int?filterCount = null) { var model = _headerMapper.Map(entities[0]); model.ReceiptDetail = new EnumerableResponse <ReceiptDetail>(); var receiptDetail = new List <ReceiptDetail>(); var startIndex = CommonUtil.ComputeStartIndex(detailPageNumber, detailPageSize); var endIndex = CommonUtil.ComputeEndIndex(detailPageNumber, detailPageSize, filterCount); var loopCounterEntity1 = 1; var lineNumber = startIndex != 0 ? startIndex : 1; int totalDetailRecords; // Map detail entities based on the page number and page size if (detailPageNumber.HasValue && detailPageSize.HasValue) { entities[1].Top(); do { if (loopCounterEntity1 >= startIndex) { lineNumber = AddReceiptDetail(entities[1], lineNumber, receiptDetail); } loopCounterEntity1++; } while (loopCounterEntity1 <= endIndex && entities[1].Next()); totalDetailRecords = filterCount != null && filterCount.Value != 0 ? filterCount.Value: Helper.GetRecordCount(entities[1]); } else { receiptDetail.Add(_detailMapper.Map(entities[1])); totalDetailRecords = filterCount != null && filterCount.Value != 0 ? filterCount.Value : 0; } model.ReceiptDetail.Items = receiptDetail; model.ReceiptDetail.TotalResultsCount = totalDetailRecords; return((ReceiptHeader)model); }
/// <summary> /// Method to Add Receipt detail. /// </summary> /// <param name="detailEntity">Detail Entity</param> /// <param name="lineNumber">Line Number</param> /// <param name="receiptDetail">Receipt Detail</param> /// <returns>Line Number</returns> private int AddReceiptDetail(IBusinessEntity detailEntity, int lineNumber, List <ReceiptDetail> receiptDetail) { var firstItem = _detailMapper.Map(detailEntity); // Set the pointer to the current row _detailMapper.MapKey(firstItem, detailEntity); var isSuccess = detailEntity.Read(false); firstItem.LineNumber = lineNumber; if (isSuccess) { receiptDetail.Add(firstItem); } lineNumber++; return(lineNumber); }