Exemple #1
0
        //DepositPost
        public ATMDeposit_ViewModel DepositPost(int sessionID, ATMDeposit_ViewModel models)
        {
            NWBAEntities db = new NWBAEntities();

            int accountNumber = models.ToAccountNumber;

            if (accountNumber != 0)
            {
                var accountQuery = Repo.GetAccount(accountNumber);
                decimal amount = models.Amount;

                decimal newBalance = accountQuery.Balance + amount;
                DateTime modifiedDate = System.DateTime.Now;

                Account updateAccount = Repo.GetAccount(accountNumber);
                updateAccount.Balance = newBalance;
                updateAccount.ModifyDate = modifiedDate;

                Repo.UpdateExistingAccount(updateAccount);

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

                models.Message = "Deposit SUCCESSFUL.";

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

                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(sessionID);

                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 Deposit(ATMDeposit_ViewModel models)
        {
            int sessionUserID = WebSecurity.GetUserId(User.Identity.Name);
            Bank bank = new Bank();

            ATMDeposit_ViewModel depositView;

            if (ModelState.IsValid)
            {
                depositView = bank.DepositPost(sessionUserID, models);
            }
            else
            {
                return Deposit();
            }

            return View(depositView);
        }
Exemple #3
0
        //DepositGet
        public ATMDeposit_ViewModel Deposit(int sessionUserID)
        {
            var customerQuery = Repo.GetCustomerSingle(sessionUserID);
            var accountQuery = Repo.GetCustomerAccountQueryable(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
            });

            //Create a viewmodel and populate it with data
            var newModel = new ATMDeposit_ViewModel()
            {
                CustomerName = customerQuery.CustomerName,
                AccountList = accounts,
            };
            return newModel;
        }