Example #1
0
        public async void addTransaction(string CustomerID, TransactionTypes transactionType, DateTime transactionTime, float amount, Currency currency, string sourceAccountNumber, string destnationAccountNumber = null)
        {
            AccountTransactionRepository transactionRepository = new AccountTransactionRepository(this._context);

            CustomerRepository    customerRepository = new CustomerRepository(this._context);
            BankAccountRepository accountRepository  = new BankAccountRepository(this._context);

            var customer = customerRepository.getByCustomerID(CustomerID);

            if (customer == null)
            {
                throw new Exception(string.Format("there's no customer with that customerID'{0}'", CustomerID));
            }

            var sourceAccount = accountRepository.getByAccountNumber(sourceAccountNumber);

            if (customer == null)
            {
                throw new Exception(string.Format("Source Bank Account Error:there's no BankAccount with that AccountNumber'{0}'", sourceAccountNumber));
            }

            DAL.Entities.BankAccount destnationAccount = null;
            if (transactionType == TransactionTypes.transfer)
            {
                destnationAccount = accountRepository.getByAccountNumber(destnationAccountNumber);
                if (destnationAccount == null)
                {
                    throw new Exception(string.Format("Destnation Bank Account Error:there's no BankAccount with that AccountNumber'{0}'", destnationAccountNumber));
                }
            }

            await transactionRepository.addTransaction(customer, transactionType, transactionTime, amount, currency, sourceAccount, destnationAccount);
        }
 public AccountTransactionRepositoryTest()
 {
     DbContextInMemory = GetInMemoryDbContext();
     MappingConfig     = new MapperConfiguration(cfg => { cfg.AddProfile(new MappingProfile()); });
     Mapper            = MappingConfig.CreateMapper();
     AccountTransactionRepositoryUnderTest = new AccountTransactionRepository(DbContextInMemory);
 }
        /// <summary>
        /// Class constructor.
        /// </summary>
        /// <param name="accountRepository"><see cref="AccountRepository"/> reference, received via dependency injection.</param>
        /// <param name="AccountTransactionRepository"><see cref="AccountTransactionRepository"/> reference, received via dependency injection.</param>
        public RepositoryFactory(AccountRepository accountRepository,
                                 AccountTransactionRepository accountTransactionRepository)
        {
            _accountRepository            = accountRepository;
            _accountTransactionRepository = accountTransactionRepository;

            SetupAccountRepository();
            SetupAccountTransactionRepository();
        }
 /// <summary>
 /// Initialize Account Transactions Controller services..
 /// </summary>
 /// <param name="accountTransactionRepository"><see cref="AccountTransactionRepository"/> reference via dependency injection.</param>
 /// <param name="accountRepository"><see cref="AccountRepository"/> reference via dependency injection.</param>
 /// <param name="repositoryFactory"><see cref="RepositoryFactory"/> reference via dependency injection.</param>
 /// <param name="accountsTransactionHandler"><see cref="AccountTransactionsHandler"/> reference via dependency injection.</param>
 public AccountTransactionController(AccountTransactionRepository accountTransactionRepository,
                                     AccountRepository accountRepository,
                                     RepositoryFactory repositoryFactory,
                                     AccountTransactionsHandler accountsTransactionHandler)
 {
     _accountTransactionRepository = accountTransactionRepository;
     _accountRepository            = accountRepository;
     _repositoryFactory            = repositoryFactory;
     _accountsTransactionHandler   = accountsTransactionHandler;
 }
Example #5
0
        public dynamic GetRollingTwelveMonthGasSummary()
        {
            dynamic items = null;

            using (AccountTransactionRepository accountTransactionRepository = new AccountTransactionRepository(_appConfiguration["DatabaseConnectionString"].Value.ToString()))
            {
                IDictionary <string, object> parameters = new Dictionary <string, object>();

                items = accountTransactionRepository.ExecuteStoredProcedureCommand(_appConfiguration["GetMonthlyGasSummaryByYearCommandText"].Value.ToString(), parameters);
            }

            return(items);
        }
Example #6
0
        public dynamic GetYearlyTransactionSourceSummary(int year)
        {
            dynamic items = null;

            using (AccountTransactionRepository accountTransactionRepository = new AccountTransactionRepository(_appConfiguration["DatabaseConnectionString"].Value.ToString()))
            {
                IDictionary <string, object> parameters = new Dictionary <string, object>();

                parameters.Add("year", year);

                items = accountTransactionRepository.ExecuteStoredProcedureCommand(_appConfiguration["GetYearlyTransactionSourceSummaryCommandText"].Value.ToString(), parameters);
            }

            return(items);
        }
Example #7
0
        public dynamic GetCurrentMonthAccountTransactions()
        {
            dynamic items = null;

            using (AccountTransactionRepository accountTransactionRepository = new AccountTransactionRepository(_appConfiguration["DatabaseConnectionString"].Value.ToString()))
            {
                IDictionary <string, object> parameters = new Dictionary <string, object>();

                parameters.Add("Year", DateTime.Today.Year);
                parameters.Add("Month", DateTime.Today.Month);

                items = accountTransactionRepository.ExecuteStoredProcedureCommand(_appConfiguration["GetAccountTransactionsPerYearMonthCommandText"].Value.ToString(), parameters);
            }

            return(items);
        }
Example #8
0
        private dynamic getDebitCreditTotalsGroupByMonthByYear()
        {
            IDictionary <string, object> parameters = new Dictionary <string, object>();


            dynamic items = null;

            using (AccountTransactionRepository accountTransactionRepository = new AccountTransactionRepository(_appConfiguration["DatabaseConnectionString"].Value.ToString()))
            {
                items = accountTransactionRepository.ExecuteStoredProcedureCommand(_appConfiguration["GetDebitCreaditTotalsGroupByMonthByYearCommandText"].Value.ToString(), parameters);
            }



            return(items);
        }
Example #9
0
        public object GetGasSpendingDetailsByYearAndMonth(int year, int month)
        {
            dynamic items = null;

            using (AccountTransactionRepository accountTransactionRepository = new AccountTransactionRepository(_appConfiguration["DatabaseConnectionString"].Value.ToString()))
            {
                IDictionary <string, object> parameters = new Dictionary <string, object>();

                parameters.Add("Year", year);
                parameters.Add("Month", month);

                items = accountTransactionRepository.ExecuteStoredProcedureCommand(_appConfiguration["GetGasSpendingDetailsByYearAndMonthCommandText"].Value.ToString(), parameters);
            }

            return(items);
        }
Example #10
0
        private IEnumerable <ITransactionType> getTransactionTypes()
        {
            string name = System.Reflection.MethodBase.GetCurrentMethod().Name;
            List <ITransactionType> result = new List <ITransactionType>();
            string cacheKey = _appConfiguration["ResultSetCacheKey:TransactionTypes"].Value.ToString();

            if (!_memoryCache.TryGetValue(cacheKey, out result))
            {
                lock (CacheLockObject)
                {
                    IEnumerable <TransactionTypeResult> items = null;
                    using (AccountTransactionRepository accountTransactionRepository = new AccountTransactionRepository(_appConfiguration["DatabaseConnectionString"].Value.ToString()))
                    {
                        items = accountTransactionRepository.GetAll <TransactionTypeResult>(typeof(TransactionType)).ToList();
                    }


                    if (result == null)
                    {
                        result = new List <ITransactionType>();
                    }
                    items.ToList().ForEach(x =>
                    {
                        using (TransactionTypeBuilder builder = new TransactionTypeBuilder())
                        {
                            builder.Build(x);
                            result.Add(builder.GetResult() as TransactionType);
                        }
                    });

                    // Set cache options.
                    var cacheEntryOptions = new MemoryCacheEntryOptions()
                                            // Keep in cache for this time, reset time if accessed.
                                            .SetSlidingExpiration(TimeSpan.FromHours(3));

                    _memoryCache.Set(cacheKey, result, cacheEntryOptions);
                }
            }


            return(result);
        }
Example #11
0
        public void UpdateAccountTransaction(UpdateAccountTransactionPayload payloadData)
        {
            AccountTransactionResult accountTransactionResult = new AccountTransactionResult();

            accountTransactionResult.AccountTransactionId = payloadData.AccountTransactionId;
            accountTransactionResult.Date                = payloadData.Date;
            accountTransactionResult.Amount              = payloadData.Amount;
            accountTransactionResult.TransactionTypeId   = payloadData.TransactionTypeId;
            accountTransactionResult.TransactionSourceId = payloadData.TransactionSourceId;
            accountTransactionResult.Notes               = payloadData.Note;


            TransactionSourceResult transactionSourceResult = new TransactionSourceResult();

            transactionSourceResult.Name = payloadData.TransactionSourceName;
            using (AccountTransactionRepository accountTransactionRepository = new AccountTransactionRepository(_appConfiguration["DatabaseConnectionString"].Value.ToString()))
            {
                try
                {
                    accountTransactionRepository.BeginTransaction();

                    if (accountTransactionResult.TransactionSourceId == 0)
                    {
                        accountTransactionResult.TransactionSourceId = accountTransactionRepository.Insert <TransactionSourceResult>(typeof(TransactionSource), transactionSourceResult);
                    }

                    accountTransactionRepository.Update <AccountTransactionResult>(typeof(AccountTransaction), accountTransactionResult);

                    accountTransactionRepository.CommitTransaction();

                    clearMemoryCache();
                }
                catch (Exception)
                {
                    accountTransactionRepository.RollbackTransaction();
                    throw;
                }
            }
        }