Example #1
0
        public async Task <byte[]> DownloadFilteredExcelFileAsync(TransactionFilterConfig transactionFilterConfig)
        {
            var workbook  = new XLWorkbook();
            var worksheet = workbook.Worksheets.Add("Transactions");

            transactionFilterConfig.XlLetterGenerate();

            TransactionDTO[] transactionDTOs = await GetFilteredAsync(transactionFilterConfig.StatusColumn.Value, transactionFilterConfig.TypeColumn.Value,
                                                                      transactionFilterConfig.ClientNameColumn.Value);

            if (!string.IsNullOrEmpty(transactionFilterConfig.IdColumn.XlLetter))
            {
                worksheet.Cell(1, transactionFilterConfig.IdColumn.XlLetter).Value = "TransactionId";
            }
            if (!string.IsNullOrEmpty(transactionFilterConfig.StatusColumn.XlLetter))
            {
                worksheet.Cell(1, transactionFilterConfig.StatusColumn.XlLetter).Value = "Status";
            }
            if (!string.IsNullOrEmpty(transactionFilterConfig.TypeColumn.XlLetter))
            {
                worksheet.Cell(1, transactionFilterConfig.TypeColumn.XlLetter).Value = "Type";
            }
            if (!string.IsNullOrEmpty(transactionFilterConfig.ClientNameColumn.XlLetter))
            {
                worksheet.Cell(1, transactionFilterConfig.ClientNameColumn.XlLetter).Value = "ClientName";
            }
            if (!string.IsNullOrEmpty(transactionFilterConfig.AmountColumn.XlLetter))
            {
                worksheet.Cell(1, transactionFilterConfig.AmountColumn.XlLetter).Value = "Amount";
            }

            int sheetRow = 2;

            foreach (TransactionDTO transactionDTO in transactionDTOs)
            {
                if (!string.IsNullOrEmpty(transactionFilterConfig.IdColumn.XlLetter))
                {
                    worksheet.Cell(sheetRow, transactionFilterConfig.IdColumn.XlLetter).Value = transactionDTO.TransactionId;
                }
                if (!string.IsNullOrEmpty(transactionFilterConfig.StatusColumn.XlLetter))
                {
                    worksheet.Cell(sheetRow, transactionFilterConfig.StatusColumn.XlLetter).Value = transactionDTO.Status;
                }
                if (!string.IsNullOrEmpty(transactionFilterConfig.TypeColumn.XlLetter))
                {
                    worksheet.Cell(sheetRow, transactionFilterConfig.TypeColumn.XlLetter).Value = transactionDTO.Type;
                }
                if (!string.IsNullOrEmpty(transactionFilterConfig.ClientNameColumn.XlLetter))
                {
                    worksheet.Cell(sheetRow, transactionFilterConfig.ClientNameColumn.XlLetter).Value = transactionDTO.ClientName;
                }
                if (!string.IsNullOrEmpty(transactionFilterConfig.AmountColumn.XlLetter))
                {
                    worksheet.Cell(sheetRow, transactionFilterConfig.AmountColumn.XlLetter).Value = transactionDTO.Amount;
                }
                sheetRow++;
            }

            worksheet.Columns().AdjustToContents();

            using (MemoryStream stream = new MemoryStream())
            {
                workbook.SaveAs(stream);
                return(stream.ToArray());
            }
        }
Example #2
0
 public async Task <byte[]> DownloadFilteredExcelFileAsync(TransactionFilterConfig transactionFilterConfig)
 {
     return(await _transactionRepository.DownloadFilteredExcelFileAsync(transactionFilterConfig));
 }