public void TestTransactionPost_Valid()
        {
            #region ASSIGN

            TestRepository                tRepo       = new TestRepository();
            AccountsController            tController = null;
            CustomerAccountTransactionsVM tVM         = tRepo.GetAllTransactions(0, 0);

            tController = new AccountsController(tRepo)
            {
                ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserA"),
            };

            #endregion

            #region ACT

            var tResult = tController.Transactions(0, tVM);

            #endregion

            #region ASSERT

            Assert.IsTrue(tResult is ViewResult);
            Assert.AreEqual(((tResult as ViewResult).Model as CustomerAccountTransactionsVM).Customer.ID, 0);
            Assert.AreEqual(((tResult as ViewResult).Model as CustomerAccountTransactionsVM).Account.ID, 0);
            Assert.IsTrue(((tResult as ViewResult).Model as CustomerAccountTransactionsVM).AccountTransactions.Count > 0);

            #endregion
        }
        public void TestTransactionPost_UnauthorizedAccountOwner()
        {
            #region ASSIGN

            TestRepository                tRepo       = new TestRepository();
            AccountsController            tController = null;
            CustomerAccountTransactionsVM tVM         = tRepo.GetAllTransactions(0, 0);

            tController = new AccountsController(tRepo)
            {
                ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserB"),
            };

            #endregion

            #region ACT

            var tResult = tController.Transactions(0, tVM);

            #endregion

            #region ASSERT

            Assert.IsTrue(tResult is RedirectToActionResult);
            Assert.AreEqual((tResult as RedirectToActionResult).ActionName, "Index");

            #endregion
        }
        public CustomerAccountTransactionsVM GetAllTransactions(int customerID, int accountID, DateTime startDate, DateTime endDate, int resultLimit)
        {
            CustomerAccountTransactionsVM result = new CustomerAccountTransactionsVM();

            try
            {
                Customer tempCustomer = myContext.Customers.Where(c => c.ID == customerID).FirstOrDefault();
                Account  tempAccount  = myContext.Accounts.Where(a => a.ID == accountID).FirstOrDefault();

                // Check if owning customer.
                if (tempAccount.CustomerID == tempCustomer.ID)
                {
                    // Build query results, based on time span.
                    var query = myContext.AccountTransactions.Where(t => t.AccountID == accountID &&
                                                                    startDate <= t.TimeStamp &&
                                                                    t.TimeStamp <= endDate).
                                OrderBy(t => t.TimeStamp);

                    // Take last limit number from query, or whole query if too small.
                    List <AccountTransaction> tempTransactions = query.Skip(Math.Max(0, query.Count() - resultLimit)).ToList();

                    // Prepare view model for return.
                    result.Customer            = tempCustomer;
                    result.Account             = tempAccount;
                    result.AccountTransactions = tempTransactions;
                }
                else
                {
                    // Unauthorized user attempting to access an account not their's.
                    throw new UnauthorizedAccessException(string.Format("CUSTOMER #{0} DOES NOT HAVE ACCESS TO ACCOUNT #{1}", customerID, accountID));
                }
            }
            catch (UnauthorizedAccessException WTF)
            {
                Console.WriteLine(WTF);
                throw;
            }
            catch (Exception WTF)
            {
                Console.WriteLine(WTF);
                throw;
            }
            finally
            {
            }

            return(result);
        }
        public CustomerAccountTransactionsVM GetAllTransactions(int customerID, int accountID, DateTime startDate, DateTime endDate)
        {
            CustomerAccountTransactionsVM result = new CustomerAccountTransactionsVM();

            try
            {
                Customer tempCustomer = myContext.Customers.Where(c => c.ID == customerID).FirstOrDefault();
                Account  tempAccount  = myContext.Accounts.Where(a => a.ID == accountID).FirstOrDefault();

                // Check if owning customer.
                if (tempAccount.CustomerID == tempCustomer.ID)
                {
                    // Limit return transaction list to specified period.
                    List <AccountTransaction> tempTransactions = myContext.AccountTransactions.
                                                                 Where(t => t.AccountID == accountID &&
                                                                       startDate <= t.TimeStamp &&
                                                                       t.TimeStamp <= endDate).
                                                                 OrderBy(t => t.TimeStamp).ToList();

                    // Prepare view model for return.
                    result.Customer            = tempCustomer;
                    result.Account             = tempAccount;
                    result.AccountTransactions = tempTransactions;
                }
                else
                {
                    // Unauthorized user attempting to access an account not their's.
                    throw new UnauthorizedAccessException(string.Format("CUSTOMER #{0} DOES NOT HAVE ACCESS TO ACCOUNT #{1}", customerID, accountID));
                }
            }
            catch (UnauthorizedAccessException WTF)
            {
                Console.WriteLine(WTF);
                throw;
            }
            catch (Exception WTF)
            {
                Console.WriteLine(WTF);
                throw;
            }
            finally
            {
            }

            return(result);
        }
示例#5
0
        public CustomerAccountTransactionsVM GetAllTransactions(int customerID, int accountID)
        {
            CustomerAccountTransactionsVM result = null;

            var query = Accounts.Where(a => a.ID == accountID && a.CustomerID == customerID);

            if (query.Count() > 0)
            {
                result         = new CustomerAccountTransactionsVM();
                result.Account = query.FirstOrDefault();

                result.AccountTransactions      = AccountTransactions.Where(t => t.AccountID == accountID).OrderBy(t => t.TimeStamp).ToList();
                result.Customer                 = Customers.Where(c => c.ID == customerID).FirstOrDefault();
                result.AccountTransactionStates = GetTransactionStates();
            }

            return(result);
        }
示例#6
0
        public CustomerAccountTransactionsVM GetAllTransactions(int customerID, int accountID, DateTime startDate, DateTime endDate, int resultLimit)
        {
            CustomerAccountTransactionsVM result = null;

            var query = Accounts.Where(a => a.ID == accountID && a.CustomerID == customerID);

            if (query.Count() > 0)
            {
                result         = new CustomerAccountTransactionsVM();
                result.Account = query.FirstOrDefault();

                var query2 = AccountTransactions.Where(t => t.AccountID == accountID &&
                                                       t.TimeStamp > startDate &&
                                                       t.TimeStamp < endDate)
                             .OrderBy(t => t.TimeStamp).ToList();
                result.AccountTransactions      = query2.Skip(Math.Max(0, query2.Count() - resultLimit)).ToList();
                result.Customer                 = Customers.Where(c => c.ID == customerID).FirstOrDefault();
                result.AccountTransactionStates = GetTransactionStates();
            }

            return(result);
        }
示例#7
0
        public IActionResult Transactions(int?id, [Bind("Customer,Account,AccountTransaction,StartDate,EndDate,Limit,AccountTransactionStates")] CustomerAccountTransactionsVM accountPost)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            // Check if customer is registered.
            string guid = GetUserGuID();

            if (_repo.IsCustomerPresent(guid))
            {
                // Display Main Account page.
                try
                {
                    Customer currentCustomer = _repo.GetCustomer(guid);

                    if (currentCustomer != null)
                    {
                        Account currentAccount = _repo.GetAccountInformation(currentCustomer.ID, id.Value);
                        CustomerAccountTransactionsVM customerTransactions = null;

                        // Check limit settings.
                        int limit = -1;
                        switch (accountPost.Limit)
                        {
                        case 3:
                            // Limit 10.
                            limit = 50;
                            break;

                        case 2:
                            // Limit 10.
                            limit = 25;
                            break;

                        case 1:
                            // Limit 10.
                            limit = 10;
                            break;

                        case 0:
                        default:
                            // All transactions.
                            limit = -1;
                            break;
                        }

                        // Check if date ranges are not the same.
                        if (accountPost.StartDate.Subtract(accountPost.EndDate).TotalDays < 0)
                        {
                            // Check if limit was set.
                            if (limit > 0)
                            {
                                customerTransactions = _repo.GetAllTransactions(currentCustomer.ID, currentAccount.ID, accountPost.StartDate, accountPost.EndDate, limit);
                            }
                            else
                            {
                                customerTransactions = _repo.GetAllTransactions(currentCustomer.ID, currentAccount.ID, accountPost.StartDate, accountPost.EndDate);
                            }
                        }
                        else
                        {
                            // Check if limit was set.
                            if (limit > 0)
                            {
                                customerTransactions = _repo.GetAllTransactions(currentCustomer.ID, currentAccount.ID, limit);
                            }
                            else
                            {
                                customerTransactions = _repo.GetAllTransactions(currentCustomer.ID, currentAccount.ID);
                            }

                            accountPost.StartDate = DateTime.Now;
                            accountPost.EndDate   = accountPost.StartDate;
                        }

                        // Restore old values.
                        customerTransactions.StartDate = accountPost.StartDate;
                        customerTransactions.EndDate   = accountPost.EndDate;
                        customerTransactions.Limit     = accountPost.Limit;
                        customerTransactions.AccountTransactionStates = _repo.GetTransactionStates();

                        List <TransactionLimitVM> tempList = new List <TransactionLimitVM>()
                        {
                            new TransactionLimitVM()
                            {
                                ID = 0, Name = "All"
                            },
                            new TransactionLimitVM()
                            {
                                ID = 1, Name = "10"
                            },
                            new TransactionLimitVM()
                            {
                                ID = 2, Name = "25"
                            },
                            new TransactionLimitVM()
                            {
                                ID = 3, Name = "50"
                            },
                        };
                        ViewData["Limit"] = new SelectList(tempList, "ID", "Name", customerTransactions.Limit);

                        return(View(customerTransactions));
                    }
                }
                catch (Exception WTF)
                {
                    Console.WriteLine(WTF);
                    return(RedirectToAction(nameof(Index)));
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                // Redirect to create customer information page.
                return(RedirectToAction(nameof(Create), "Customers"));
            }
        }
示例#8
0
        public IActionResult Transactions(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            // Check if customer is registered.
            string guid = GetUserGuID();

            if (_repo.IsCustomerPresent(guid))
            {
                // Display Main Account page.
                try
                {
                    Customer currentCustomer = _repo.GetCustomer(guid);

                    if (currentCustomer != null)
                    {
                        Account currentAccount = _repo.GetAccountInformation(currentCustomer.ID, id.Value);
                        CustomerAccountTransactionsVM customerTransactions = _repo.GetAllTransactions(currentCustomer.ID, id.Value);
                        customerTransactions.StartDate = DateTime.Now;
                        customerTransactions.EndDate   = DateTime.Now;
                        customerTransactions.Limit     = 0;
                        customerTransactions.AccountTransactionStates = _repo.GetTransactionStates();

                        List <TransactionLimitVM> tempList = new List <TransactionLimitVM>()
                        {
                            new TransactionLimitVM()
                            {
                                ID = 0, Name = "All"
                            },
                            new TransactionLimitVM()
                            {
                                ID = 1, Name = "10"
                            },
                            new TransactionLimitVM()
                            {
                                ID = 2, Name = "25"
                            },
                            new TransactionLimitVM()
                            {
                                ID = 3, Name = "50"
                            },
                        };

                        ViewData["Limit"] = new SelectList(tempList, "ID", "Name", customerTransactions.Limit);

                        return(View(customerTransactions));
                    }
                }
                catch (Exception WTF)
                {
                    Console.WriteLine(WTF);
                    return(RedirectToAction(nameof(Index)));
                }
                return(RedirectToAction(nameof(Index), "Customers"));
            }
            else
            {
                // Redirect to create customer information page.
                return(RedirectToAction(nameof(Create), "Customers"));
            }
        }