/// <summary> /// Gets the filtered transactions ssynchronously. /// <remarks>If this method is consumed, make sure to hook to the <seealso cref="ITransactionRepository.GetTransactionsCompleted"/> event of this instance of <see cref="ITransactionRepository"/>.</remarks> /// <param name="filter">The instance of <see cref="TransactionFilter"/> that wraps all filter values.</param> /// </summary> void ITransactionRepository.GetTransactionsAsync(TransactionFilter filter) { QueueAsyncTask(() => { Exception exception = null; string message = null; IList<Transaction> transList = null; try { //This treachery is for faking a web service call. Thread.Sleep(2000); transList = GetTransactions(filter); LogUtil.LogInfo("TransactionRepository", "ITransactionRepository.GetTransactionsAsync", "Successfully acquired the list."); } catch (Exception ex) { LogUtil.LogError("TransactionRepository", "ITransactionRepository.GetTransactionsAsync", ex); exception = ex; message = ErrorMessages.ERR_FAILED_TO_LOAD_TRNS; } finally { if (null != _getTransactionsCompleted) _getTransactionsCompleted(this, new GetTransactionFinishedEventArg(exception, message, transList)); } }); }
/// <summary> /// Gets all the filtered transactions. /// </summary> private void GetFilteredTransactions() { string dateDisplayFilter = "N.A."; string fromAmountFilterDisplay = "0"; string toAmountFilterDisplay = "max"; var transactionFilter = new TransactionFilter(); if (FilterViewModel.IsDateRangeIncluded) { transactionFilter.FromDate = FilterViewModel.FromDate; transactionFilter.ToDate = FilterViewModel.ToDate; dateDisplayFilter = string.Format("{0} - {1}", FilterViewModel.FromDate, FilterViewModel.ToDate); } if (null != FilterViewModel.FromAmount) { double amount = 0; if (double.TryParse(FilterViewModel.FromAmount, out amount)) { transactionFilter.FromAmount = amount; fromAmountFilterDisplay = Convert.ToString(amount); } } if (null != FilterViewModel.ToAmount) { double amount = 0; if (double.TryParse(FilterViewModel.ToAmount, out amount)) { transactionFilter.ToAmount = amount; toAmountFilterDisplay = Convert.ToString(amount); } } transactionFilter.Username = FilterViewModel.Username; if (!IsUserAdmin)//Override selected user name if user is not admin transactionFilter.Username = AppData.LoggedInUser.Username; //Update properties for the filter visual TotalIncome = 0; TotalExpenditure = 0; FilterDisplayOnDates = dateDisplayFilter; FilterDisplayOnAmount = string.Format("{0} - {1}", fromAmountFilterDisplay, toAmountFilterDisplay); FilterDisplayOnUser = FilterViewModel.Username ?? "N.A."; _transactionRepository.GetTransactionsAsync(transactionFilter); }
/// <summary> /// Gets a list of <see cref="Transaction"/> instances. /// </summary> /// <param name="filter">The instance of <see cref="TransactionFilter"/> that wraps all filter values.</param> /// <returns>A list of transactions <see langword="null"/> if none are there.</returns> IList<Transaction> ITransactionRepository.GetTransactions(TransactionFilter filter) { return GetTransactions(filter); }
/// <summary> /// Gets the transactions. /// </summary> /// <param name="filter"></param> /// <returns></returns> private IList<Transaction> GetTransactions(TransactionFilter filter) { if (filter == null) throw new ArgumentNullException("filter"); using (var session = SessionProvider.SessionFactory.OpenSession()) { //Build the criteria. ICriteria criteria = session.CreateCriteria<Transaction>(); if (filter.FromDate.HasValue && filter.ToDate.HasValue) { criteria.Add(Restrictions.Between("TransactionDate", filter.FromDate.Value, filter.ToDate.Value)); } if (filter.FromAmount.HasValue && filter.ToAmount.HasValue) { criteria.Add(Restrictions.Between("Amount", filter.FromAmount.Value, filter.ToAmount.Value)); } if (!string.IsNullOrEmpty(filter.Username)) { criteria.Add(Restrictions.Eq("CreatedBy", filter.Username)); } return criteria.List<Transaction>(); } }