示例#1
0
        private async Task <IDictionary <string, InvoiceIataSpecificData> > GetIataSpecificDataAsync(
            HistoryOperationViewModel[] historyOperations)
        {
            var invoiceIds = historyOperations.Where(o => !string.IsNullOrEmpty(o.InvoiceId)).Select(o => o.InvoiceId)
                             .Distinct();

            var results = new ConcurrentDictionary <string, InvoiceIataSpecificData>();

            foreach (var batch in invoiceIds.Batch(BatchPieceSize))
            {
                await Task.WhenAll(batch.Select(id =>
                                                _iataService.GetIataSpecificDataAsync(id).ContinueWith(t => results[id] = t.Result)));
            }

            return(results);
        }
        private async Task FillAdditionalData(IReadOnlyList <InvoiceResponseModel> result, bool isDispute = false)
        {
            foreach (var invoice in result)
            {
                invoice.MerchantName = await _merchantService.GetMerchantNameAsync(invoice.MerchantId);

                var iataSpecificData = await _iataService.GetIataSpecificDataAsync(invoice.Id);

                if (iataSpecificData != null)
                {
                    invoice.IataInvoiceDate       = iataSpecificData.IataInvoiceDate;
                    invoice.SettlementMonthPeriod = iataSpecificData.SettlementMonthPeriod;
                }

                invoice.LogoUrl = isDispute
                    ? await _merchantService.GetMerchantLogoUrlAsync(invoice.ClientName)
                    : await _merchantService.GetMerchantLogoUrlAsync(invoice.MerchantId);

                // if an invoice partially paid, it shows the amount left to pay
                if (invoice.Status == InvoiceStatus.Underpaid.ToString() && invoice.LeftAmountToPayInSettlementAsset > 0)
                {
                    invoice.Amount = invoice.LeftAmountToPayInSettlementAsset;
                }
            }
        }