Exemplo n.º 1
0
        public async Task <OperationDataResult <List <TransactionModel> > > GetTransactionsPageAsync(GetTransactionsPageModel getTransactionsPageModel)
        {
            // TODO: refactor
            var transactionsPage = await _applicationContext.Transactions
                                   .Where(transaction =>
                                          (getTransactionsPageModel.Statuses == null)?true
                                          : getTransactionsPageModel.Statuses.Contains(transaction.Status))
                                   .Where(transaction =>
                                          (getTransactionsPageModel.Types == null) ? true
                      : getTransactionsPageModel.Types.Contains(transaction.Type))
                                   .AsNoTracking()
                                   .OrderBy(transaction => transaction.Id)
                                   .Skip((getTransactionsPageModel.PageNumber - 1) * getTransactionsPageModel.NumberOfItemsPerPage)
                                   .Take(getTransactionsPageModel.NumberOfItemsPerPage)
                                   .Select(transaction => new TransactionModel
            {
                Id         = transaction.Id,
                Status     = transaction.Status,
                Type       = transaction.Type,
                ClientName = transaction.Client.Name,
                Amount     = transaction.Amount
            })
                                   .ToListAsync();

            return(new OperationDataResult <List <TransactionModel> >(true, transactionsPage));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetTransactionsPage([FromQuery] GetTransactionsPageModel getTransactionsPageModel)
        {
            var result = await _transactionService.GetTransactionsPageAsync(getTransactionsPageModel);

            return(result.Success ? (IActionResult)Ok(result.Model) : BadRequest(result.Message));
        }