Exemple #1
0
        //WithdrawalPost
        public ATMWithdraw_ViewModel WithdrawalPost(int sessionUserID, ATMWithdraw_ViewModel models)
        {
            NWBAEntities db = new NWBAEntities();

            int accountNumber = models.FromAccountNumber;
            var accountQuery = Repo.GetAccount(accountNumber);

            if (accountNumber != 0)
            {
                decimal amount = models.Amount;
                decimal newBalance;
                decimal balanceThreshold;
                int transactionCountCheck = calculateTransactionCount(accountNumber);

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

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

                if (newBalance >= balanceThreshold)
                {
                    DateTime modifiedDate = System.DateTime.Now;

                    Account updateAccount = db.Accounts.First(i => i.AccountNumber.Equals(accountNumber));
                    updateAccount.Balance = newBalance;
                    updateAccount.ModifyDate = modifiedDate;

                    Repo.UpdateExistingAccount(updateAccount);

                    Transaction newTransaction = new Transaction
                    {
                        TransactionType = "W",
                        AccountNumber = accountNumber,
                        Amount = amount,
                        Comment = models.Comment,
                        ModifyDate = modifiedDate
                    };
                    Repo.AddTransaction(newTransaction);

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

                    models.Message = "Withdrawal SUCCESSFUL.";
                }
                else
                {
                    models.Message = "Withdrawal UNSUCCESSFUL.";
                }
            }
            var accountListQuery = Repo.GetCustomerAccountQueryable(sessionUserID);

            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
            });

            Customer customerQuery = Repo.GetCustomerSingle(sessionUserID);

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

            models.AccountList = accounts;
            models.CustomerName = customerQuery.CustomerName;
            models.AccountBalanceMessage = "Account Balance: " + formatAccountBalance;

            return models;
        }
        public ActionResult Withdrawal(ATMWithdraw_ViewModel models)
        {
            int sessionUserID = WebSecurity.GetUserId(User.Identity.Name);
            Bank bank = new Bank();

            ATMWithdraw_ViewModel withdrawalView;

            if (ModelState.IsValid)
            {
                withdrawalView = bank.WithdrawalPost(sessionUserID, models);
            }
            else
            {
                return Withdrawal();
            }

            return View(withdrawalView);
        }
Exemple #3
0
        //WithdrawalGet
        public ATMWithdraw_ViewModel Withdrawal(int sessionUserID)
        {
            var customerQuery = Repo.GetCustomerSingle(sessionUserID);
            var customerAccountListQuery = Repo.GetCustomerAccountQueryable(sessionUserID);

            IEnumerable<SelectListItem> accounts = customerAccountListQuery.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 newModel = new ATMWithdraw_ViewModel()
            {
                CustomerName = customerQuery.CustomerName,
                AccountList = accounts,
            };

            return newModel;
        }