public IEnumerable <Transaction> GetTransactionBySearch(TransactionSearchValue searchValue) { var transactions = Repository.GetAll(); if (searchValue.AmountRange.From.HasValue) { transactions = transactions.Where(transaction => transaction.Amount >= searchValue.AmountRange.From); } if (searchValue.AmountRange.To.HasValue) { transactions = transactions.Where(transaction => transaction.Amount <= searchValue.AmountRange.To); } if (searchValue.CreditCardType != null) { transactions = transactions.Where(transaction => transaction.CreditCardType.Id == searchValue.CreditCardType.Id); } if (searchValue.CurrencyType != null) { transactions = transactions.Where(transaction => transaction.CurrencyType.Id == searchValue.CurrencyType.Id); } if (searchValue.DateRange.From.HasValue) { transactions = transactions.Where(transaction => transaction.TransactionDate >= searchValue.DateRange.From.Value); } if (searchValue.DateRange.To.HasValue) { transactions = transactions.Where(transaction => transaction.TransactionDate <= searchValue.DateRange.To.Value); } if (searchValue.Fund != null) { transactions = transactions.Where(transaction => transaction.TransactionFunds.Any(transactionFund => transactionFund.Fund.Id == searchValue.Fund.Id)); } if (searchValue.SourceType != null) { transactions = transactions.Where(transaction => transaction.SourceTypeId == searchValue.SourceType.Id); } if (!String.IsNullOrEmpty(searchValue.TransactionCode)) { transactions = transactions.Where(transaction => transaction.TransactionCode == searchValue.TransactionCode); } return(transactions); }
private TransactionSearchValue GetSearchValue() { TransactionSearchValue searchValue = new TransactionSearchValue(); decimal? fromAmountRange = null; if (!String.IsNullOrEmpty(txtFromAmount.Text)) { fromAmountRange = Decimal.Parse(txtFromAmount.Text); } decimal? toAmountRange = null; if (!String.IsNullOrEmpty(txtToAmount.Text)) { toAmountRange = Decimal.Parse(txtToAmount.Text); } searchValue.AmountRange = new RangeValue<decimal?>(fromAmountRange, toAmountRange); if (ddlCreditCardType.SelectedValue != "-1") { searchValue.CreditCardType = definedValueService.Get(int.Parse(ddlCreditCardType.SelectedValue)); } if (ddlCurrencyType.SelectedValue != "-1") { searchValue.CurrencyType = definedValueService.Get(int.Parse(ddlCurrencyType.SelectedValue)); } DateTime? fromTransactionDate = null; if (!String.IsNullOrEmpty(txtFromDate.Text)) { fromTransactionDate = DateTime.Parse(txtFromDate.Text); } DateTime? toTransactionDate = null; if (!String.IsNullOrEmpty(txtToDate.Text)) { toTransactionDate = DateTime.Parse(txtToDate.Text); } searchValue.DateRange = new RangeValue<DateTime?>(fromTransactionDate, toTransactionDate); if (ddlFundType.SelectedValue != "-1") { searchValue.Fund = fundService.Get(int.Parse(ddlFundType.SelectedValue)); } searchValue.TransactionCode = txtTransactionCode.Text; searchValue.SourceType = definedValueService.Get(int.Parse(ddlSourceType.SelectedValue)); return searchValue; }