public IList <ITransaction> GetByCriteria(ITransactionCriteria criteria) { var results = GetAll(); // by Currency if (!string.IsNullOrEmpty(criteria.CurrencyCode)) { try { var allCurrencyCodes = CurrencyUtils.GetAllCurrencyCodes(); var currencyCode = CurrencyUtils.GetValidCurrencyCode(allCurrencyCodes, criteria.CurrencyCode); results = results.Where(x => x.CurrencyCode == currencyCode).ToList(); } catch (Exception ex) { _logger.Error($"Invalid currency criteria: {ex.Message}"); return(new List <ITransaction>()); } } // by Date range format dd/MM/yyyy if (!string.IsNullOrEmpty(criteria.StartDate)) { try { var startDate = DateTimeUtils.ParseDate(criteria.StartDate); results = results.Where(x => x.Date >= startDate).ToList(); } catch (Exception ex) { _logger.Error($"Invalid start date criteria: {ex.Message}"); return(new List <ITransaction>()); } } if (!string.IsNullOrEmpty(criteria.EndDate)) { try { var endDate = DateTimeUtils.ParseDate(criteria.EndDate); results = results.Where(x => x.Date <= endDate).ToList(); } catch (Exception ex) { _logger.Error($"Invalid end date criteria: {ex.Message}"); return(new List <ITransaction>()); } } // by Status if (!string.IsNullOrEmpty(criteria.Status)) { results = results.Where(x => x.Status == criteria.Status).ToList(); } return(results); }
public IList <ITransaction> GetTransactionsByCriteria(ITransactionCriteria criteria) { return(_businessLogic.GetByCriteria(criteria)); }