Ejemplo n.º 1
0
        public async Task <IActionResult> GetAllTransactionByFile([FromQuery] TranactionFilrtrationQuery filter)
        {
            using (var workbook = new XLWorkbook())
            {
                var worksheet  = workbook.Worksheets.Add("Transaction");
                var currentRow = 1;
                worksheet.Cell(currentRow, 1).Value = "TransactionId";
                worksheet.Cell(currentRow, 2).Value = "Status";
                worksheet.Cell(currentRow, 3).Value = "Type";
                worksheet.Cell(currentRow, 4).Value = "ClientName";
                worksheet.Cell(currentRow, 5).Value = "Amount";

                List <Transaction> transactions = await _transactionService.GetTransactionsAsync(filter);

                foreach (var transaction in transactions)
                {
                    currentRow++;
                    worksheet.Cell(currentRow, 1).Value = transaction.TransactionId;
                    worksheet.Cell(currentRow, 2).Value = transaction.Status;
                    worksheet.Cell(currentRow, 3).Value = transaction.Type;
                    worksheet.Cell(currentRow, 4).Value = transaction.ClientName;
                    worksheet.Cell(currentRow, 5).Value = "$" + transaction.Amount;
                }

                using (var stream = new MemoryStream())
                {
                    workbook.SaveAs(stream);
                    var content = stream.ToArray();

                    return(File(content,
                                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                                "Transaction.xlsx"));
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <List <Transaction> > GetTransactionsAsync(TranactionFilrtrationQuery filter)
        {
            IQueryable <Transaction> query = _context.Transactions;

            if (filter != null)
            {
                var expressionsList = new List <Expression <Func <Transaction, bool> > >();

                if (filter.Status != null)
                {
                    Expression <Func <Transaction, bool> > statusFilter = a => a.Status == filter.Status;
                    expressionsList.Add(statusFilter);
                }

                if (filter.Type != null)
                {
                    Expression <Func <Transaction, bool> > userFilter = a => a.Type == filter.Type;
                    expressionsList.Add(userFilter);
                }

                if (filter.ClientName != null)
                {
                    Expression <Func <Transaction, bool> > nameFilter = a => a.ClientName.ToUpper().StartsWith(filter.ClientName.ToUpper());
                    expressionsList.Add(nameFilter);
                }

                Expression <Func <Transaction, bool> > expression = doctor => true;

                foreach (var exp in expressionsList)
                {
                    expression = expression.AndAlso(exp);
                }

                if (expression != null)
                {
                    query = query.Where(expression);
                }
            }

            return(await query.ToListAsync <Transaction>());
        }
Ejemplo n.º 3
0
 public async Task <IActionResult> GetAllTransaction([FromQuery] TranactionFilrtrationQuery filter)
 {
     return(Ok(await _transactionService.GetTransactionsAsync(filter)));
 }