Esempio n. 1
0
        //TransferPost
        public ATMTransfer_ViewModel TransferPost(int sessionUserID, ATMTransfer_ViewModel models)
        {
            decimal newBalanceFrom;
            decimal balanceThreshold;
            NWBAEntities db = new NWBAEntities();
            int fromAccountNumber = models.FromAccountNumber;

            if (fromAccountNumber != 0)
            {
                int toAccountNumber = models.ToAccountNumber;

                var fromAccountQuery = Repo.GetAccount(fromAccountNumber);

                int transactionCountCheck = calculateTransactionCount(fromAccountNumber);

                decimal amount = models.Amount;

                if (transactionCountCheck >= MAX_FREE_TRANSACTIONS)
                {
                    newBalanceFrom = fromAccountQuery.Balance - amount - (decimal)0.20;
                }
                else
                {
                    newBalanceFrom = fromAccountQuery.Balance - amount;
                }

                if (fromAccountQuery.AccountType.Equals("S"))
                {
                    balanceThreshold = SAVINGS_MINIMAL_BALANCE;
                }
                else
                {
                    balanceThreshold = CHECKING_MINIMAL_BALANCE;
                }

                if (newBalanceFrom >= balanceThreshold)
                {
                    DateTime modifiedDateFrom = System.DateTime.Now;

                    Account updateAccountFrom = db.Accounts.First(i => i.AccountNumber.Equals(fromAccountNumber));
                    updateAccountFrom.Balance = newBalanceFrom;
                    updateAccountFrom.ModifyDate = modifiedDateFrom;

                    Repo.UpdateExistingAccount(updateAccountFrom);

                    Transaction newTransactionWithdraw = new Transaction
                    {
                        TransactionType = "T",
                        AccountNumber = fromAccountNumber,
                        DestAccount = toAccountNumber,
                        Amount = amount,
                        Comment = models.Comment,
                        ModifyDate = modifiedDateFrom
                    };
                    Repo.AddTransaction(newTransactionWithdraw);

                    if (transactionCountCheck >= MAX_FREE_TRANSACTIONS)
                    {
                        Transaction serviceTransaction = new Transaction
                        {
                            TransactionType = "S",
                            AccountNumber = fromAccountNumber,
                            Amount = (decimal)0.20,
                            Comment = "Service Charge",
                            ModifyDate = modifiedDateFrom
                        };
                        Repo.AddTransaction(serviceTransaction);
                    }
                    else
                    {
                        Transaction serviceTransaction = new Transaction
                        {
                            TransactionType = "S",
                            AccountNumber = fromAccountNumber,
                            Amount = (decimal)0.00,
                            Comment = "Free Service Charge",
                            ModifyDate = modifiedDateFrom
                        };
                        Repo.AddTransaction(serviceTransaction);
                    }

                    if (toAccountNumber != 0)
                    {
                        var toAccountQuery = Repo.GetAccount(toAccountNumber);

                        decimal newBalanceTo = toAccountQuery.Balance + amount;
                        DateTime modifiedDateTo = System.DateTime.Now;

                        Account updateAccountTo = db.Accounts.First(i => i.AccountNumber.Equals(toAccountNumber));
                        updateAccountTo.Balance = newBalanceTo;
                        updateAccountTo.ModifyDate = modifiedDateTo;
                        Repo.UpdateExistingAccount(updateAccountTo);

                        Transaction newTransactionDeposit = new Transaction
                        {
                            TransactionType = "D",
                            AccountNumber = toAccountNumber,
                            DestAccount = toAccountNumber,
                            Amount = amount,
                            Comment = models.Comment,
                            ModifyDate = modifiedDateTo
                        };
                        Repo.AddTransaction(newTransactionDeposit);
                    }
                    models.Message = "Transfer SUCCESSFUL.";
                }
                else
                {
                    models.Message = "Transfer UNSUCCESSFUL.";
                }

                var accountListQuery = (from x in db.Accounts
                                        where x.CustomerID.Equals(sessionUserID)
                                        select x);

                var allAccountQuery = (from x in db.Accounts
                                       where x.CustomerID.Equals(sessionUserID)
                                       select x);

                IEnumerable<SelectListItem> allAccounts = allAccountQuery.OrderBy(a => a.AccountNumber).ToList().Select(a => new SelectListItem
                {
                    Value = Convert.ToString(a.AccountNumber),
                    Text = (a.AccountType.Equals("S")) ? "Savings - " + a.AccountNumber.ToString() : "Checkings - " + a.AccountNumber.ToString()
                });

                IEnumerable<SelectListItem> accounts = accountListQuery.OrderBy(a => a.AccountNumber).ToList().Select(a => new SelectListItem
                {
                    Value = Convert.ToString(a.AccountNumber),
                    Text = (a.AccountType.Equals("S")) ? "Savings - " + a.AccountNumber.ToString() + " - $" + a.Balance
                                                       : "Checkings - " + a.AccountNumber.ToString() + " - $" + a.Balance
                });

                var customerQuery = Repo.GetCustomerSingle(sessionUserID);

                decimal formatAccountBalance = Convert.ToDecimal(string.Format("{0:0.00}", fromAccountQuery.Balance));

                models.AccountList = accounts;
                models.AllAccountList = allAccounts;
                models.CustomerName = customerQuery.CustomerName;
                models.AccountBalanceMessage = "Account Balance: " + formatAccountBalance;
            }
            return models;
        }
Esempio n. 2
0
        public ActionResult Transfer(ATMTransfer_ViewModel models)
        {
            int sessionUserID = WebSecurity.GetUserId(User.Identity.Name);
            Bank bank = new Bank();

            ATMTransfer_ViewModel transferView;

            if (ModelState.IsValid)
            {
                transferView = bank.TransferPost(sessionUserID, models);
                HttpContext.Session["fromAccountNumber"] = null;
            }
            else
            {
                HttpContext.Session["fromAccountNumber"] = models.FromAccountNumber;
                return Transfer();
            }

            return View(models);
        }
Esempio n. 3
0
        //########################## DONT TOUCH BELOW UNTIL REPO FIXED
        //TransferGet
        //Transfer Page display
        public ATMTransfer_ViewModel Transfer(int sessionUserID)
        {
            NWBAEntities db = new NWBAEntities();

            var customerQuery = Repo.GetCustomerSingle(sessionUserID);
            var accountQuery = Repo.GetCustomerAccountQueryable(sessionUserID);

            if (HttpContext.Current.Session["fromAccountNumber"] != null)
            {
                int fromAccountNumber = (int)HttpContext.Current.Session["fromAccountNumber"];

                var allAccountQuery = (from x in db.Accounts
                                       where x.AccountNumber != fromAccountNumber
                                       select x);

                IEnumerable<SelectListItem> accounts = accountQuery.OrderBy(a => a.AccountNumber).ToList().Select(a => new SelectListItem
                {
                    Value = Convert.ToString(a.AccountNumber),
                    Text = (a.AccountType.Equals("S")) ? "Savings - " + a.AccountNumber.ToString() + " - $" + a.Balance
                                                           : "Checkings - " + a.AccountNumber.ToString() + " - $" + a.Balance
                });

                IEnumerable<SelectListItem> allAccounts = allAccountQuery.OrderBy(a => a.AccountNumber).ToList().Select(a => new SelectListItem
                {
                    Value = Convert.ToString(a.AccountNumber),
                    Text = (a.AccountType.Equals("S")) ? "Savings - " + a.AccountNumber.ToString() : "Checkings - " + a.AccountNumber.ToString()
                });

                var newModel = new ATMTransfer_ViewModel()
                {
                    CustomerName = customerQuery.CustomerName,
                    AccountList = accounts,
                    AllAccountList = allAccounts
                };
                return newModel;
            }
            else
            {
                //get all accounts EXCEPT the currently logged in user
                var allAccountQuery = Repo.GetAllAccountsExceptUser(sessionUserID);

                IEnumerable<SelectListItem> accounts = accountQuery.OrderBy(a => a.AccountNumber).ToList().Select(a => new SelectListItem
                {
                    Value = Convert.ToString(a.AccountNumber),
                    Text = (a.AccountType.Equals("S")) ? "Savings - " + a.AccountNumber.ToString() + " - $" + a.Balance
                                                           : "Checkings - " + a.AccountNumber.ToString() + " - $" + a.Balance
                });

                IEnumerable<SelectListItem> allAccounts = allAccountQuery.OrderBy(a => a.AccountNumber).ToList().Select(a => new SelectListItem
                {
                    Value = Convert.ToString(a.AccountNumber),
                    Text = (a.AccountType.Equals("S")) ? "Savings - " + a.AccountNumber.ToString() : "Checkings - " + a.AccountNumber.ToString()
                });

                var newModel = new ATMTransfer_ViewModel()
                {
                    CustomerName = customerQuery.CustomerName,
                    AccountList = accounts,
                    AllAccountList = allAccounts
                };
                return newModel;
            }
        }