Esempio n. 1
0
        public string ExportToCsv(BankTransactionFilters bankTransactionFilters)
        {
            var filters = new SearchPaging <BankTransactionFilters>
            {
                Page    = 1,
                Size    = 50,
                Filters = bankTransactionFilters
            };

            var bankTransactions = new List <BankTransaction>();
            var hasNext          = false;

            do
            {
                var result = this.BankTransactionRepository.Search(filters);
                bankTransactions.AddRange(result.Documents);
                hasNext = (result.Documents.Count == filters.Size);
                filters.Page++;
            }while (hasNext);

            return(this.CsvParser.Convert(bankTransactions));
        }
        private FilterDefinition <BankTransaction> SearchBankTransactionFilterBuilder(BankTransactionFilters bankTransactionFilters)
        {
            var builder = Builders <BankTransaction> .Filter;

            if (bankTransactionFilters?.StartDate == null &&
                bankTransactionFilters?.EndDate == null)
            {
                return(builder.Empty);
            }

            FilterDefinition <BankTransaction> filters = null;

            if (bankTransactionFilters.StartDate != null)
            {
                filters = builder.Gte(r => r.TransactionDate, bankTransactionFilters.StartDate.Value);
            }

            if (bankTransactionFilters.EndDate != null)
            {
                var filterByEndDate = builder.Lte(r => r.TransactionDate, bankTransactionFilters.EndDate.Value);
                filters = (filters == null) ? filterByEndDate : filters & filterByEndDate;
            }

            return(filters);
        }