Пример #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;
        }
Пример #2
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;
        }
Пример #3
0
        //StatementPost
        public Statement_ViewModel postStatement(int sessionID, Statement_ViewModel models)
        {
            using (NWBAEntities db = new NWBAEntities())
            {
                int accountID = models.AccountNumber;

                if (accountID != 0)
                {
                    var accountQuery = Repo.GetAccount(accountID);
                    var customerAccountsQuery = Repo.GetCustomerAccountQueryable(sessionID);

                    IEnumerable<SelectListItem> accounts = customerAccountsQuery.OrderBy(c => c.AccountNumber).ToList().
                         Select(c => new SelectListItem
                         {
                             Value = Convert.ToString(c.AccountNumber),
                             Text = (c.AccountType.Equals("S")) ? "Saving " + c.AccountNumber.ToString()
                             : "Checkings " + " " + c.AccountNumber.ToString()
                         });

                    decimal balance = 0;
                    decimal minSbalance = 0.20M;
                    decimal minCbalance = 200.20M;
                    decimal transactionFee = 0.20M;
                    decimal balanceThreshold;
                    Boolean check = false;

                    if (accountQuery.AccountType.Equals("S"))
                    {
                        if (accountQuery.Balance >= minSbalance)
                        {
                            balance = accountQuery.Balance - transactionFee;
                            check = true;
                        }
                        else
                        {
                            balance = accountQuery.Balance;
                        }
                    }
                    else if (accountQuery.AccountType.Equals("C"))
                    {
                        if (accountQuery.Balance >= minCbalance)
                        {
                            balance = accountQuery.Balance - transactionFee;
                            check = true;
                        }
                        else
                        {
                            balance = accountQuery.Balance;
                        }
                    }

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

                    if (balance >= balanceThreshold && check)
                    {
                        DateTime date = System.DateTime.Now;
                        Account updateAccount = db.Accounts.First(u => u.AccountNumber.Equals(accountID));
                        updateAccount.Balance = Convert.ToDecimal(string.Format("{0:0.00}", balance));
                        updateAccount.ModifyDate = date;
                        Repo.UpdateExistingAccount(updateAccount);

                        Transaction serviceTransaction = new Transaction
                        {
                            TransactionType = "S",
                            AccountNumber = accountID,
                            Amount = Convert.ToDecimal(string.Format("{0:0.00}", transactionFee)),
                            Comment = "View Statement Charge",
                            ModifyDate = date
                        };
                        Repo.AddTransaction(serviceTransaction);

                        models.retrieveMessage = "Transaction History Retrieved SUCCESSFULLY";

                        var sList = (from a in db.Transactions
                                     where a.AccountNumber.Equals(accountID)
                                     select a);

                        models.AccountNumber = accountID;
                        models.tranList = sList.ToList();
                        models.accountList = accounts;
                        models.Balance = Convert.ToDecimal(string.Format("{0:0.00}", balance));
                    }
                    else
                    {
                        models.retrieveMessage = "Transaction History Was Unable To Retrieve Due To INSUFFICIENT Amount";
                        var aList = (from a in db.Transactions
                                     where a.AccountNumber.Equals(0)
                                     select a);
                        models.AccountNumber = accountID;
                        models.accountList = accounts;
                        models.Balance = Convert.ToDecimal(string.Format("{0:0.00}", balance));
                        models.tranList = aList.ToList();
                    }
                }
                else
                {
                    return getStatement(sessionID);
                }
                return models;
            }
        }
Пример #4
0
        //################# Background BillPay Operation
        //CREATED: BY JOSH
        /* Method is in charged of performing the scheduled bill pay operation
         * It will be called by the jobs in the schduler.
         * It will create a billpay transaction.
         */
        public void processBillPay(int _accountNumber, int _payeeID, double _amount, string _date, char _period)
        {
            int senderAccountNumber = _accountNumber;
            decimal decimalAmount = (decimal)_amount;
            decimal balanceThreshold;
            decimal newBalanceFrom;
            string billPayComment = "Automated BillPay Withdraw";
            DateTime currentDate = System.DateTime.Now;

            //Rretrieve the account object from the Account table matching the account Number
            Account FoundAccount = Repo.GetAccount(senderAccountNumber);

            //Checks if if the user transaction count is less than 4. If more than 4, then apply 30cent billpay fee
            if (calculateTransactionCount(senderAccountNumber) >= MAX_FREE_TRANSACTIONS)
            {
                newBalanceFrom = FoundAccount.Balance - decimalAmount - (decimal)0.30;
            }
            else
            {
                newBalanceFrom = FoundAccount.Balance - decimalAmount;
            }

            //Determines the minimal balance threshold depending on the account
            if (FoundAccount.AccountType.Equals("S"))
            {
                balanceThreshold = SAVINGS_MINIMAL_BALANCE;
            }
            else
            {
                balanceThreshold = CHECKING_MINIMAL_BALANCE;
            }

            //Actual Billpay withdraw operation
            if (newBalanceFrom >= balanceThreshold)
            {

                FoundAccount.Balance = newBalanceFrom;
                FoundAccount.ModifyDate = currentDate;

                Repo.UpdateExistingAccount(FoundAccount);
                // Debug.WriteLine(db.Entry(FoundAccount).State);
                //db.SaveChanges(); //<-----------------------NOT SURE IF IT WILL SAVE CHANGES

                Transaction newTransactionBillPay = new Transaction
                {
                    TransactionType = "B",
                    AccountNumber = senderAccountNumber,
                    DestAccount = _payeeID,
                    Amount = decimalAmount,
                    Comment = billPayComment,
                    ModifyDate = currentDate
                };

                Repo.AddTransaction(newTransactionBillPay);

                if (calculateTransactionCount(senderAccountNumber) >= MAX_FREE_TRANSACTIONS)
                {
                    Transaction serviceTransaction = new Transaction
                    {
                        TransactionType = "S",
                        AccountNumber = senderAccountNumber,
                        Amount = (decimal)0.30,
                        Comment = "Bill Pay Service Charge",
                        ModifyDate = currentDate
                    };
                    Repo.AddTransaction(serviceTransaction);
                }
                Debug.WriteLine("Bill Pay SUCCESSFUL.");
            }
            else
            {
                Transaction newTransactionBillPay = new Transaction
                {
                    TransactionType = "F",
                    AccountNumber = senderAccountNumber,
                    DestAccount = _payeeID,
                    Amount = decimalAmount,
                    Comment = "Bill Pay Failed",
                    ModifyDate = currentDate
                };
                Repo.AddTransaction(newTransactionBillPay);
                Debug.WriteLine("Bill Pay UNSUCCESSFUL.");
            }
        }
Пример #5
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;
        }