コード例 #1
0
        public int AddTransactionSet(BankingTransaction vendTrans, List <TransactionItem> transItems)
        {
            int vendTransId = AddVendingTransaction(vendTrans.Clone());

            foreach (var item in transItems)
            {
                TransactionItem newItem = item.Clone();
                newItem.VendingTransactionId = vendTransId;
            }
            return(vendTransId);
        }
コード例 #2
0
        public BankingTransaction GetVendingTransaction(int id)
        {
            BankingTransaction item = null;

            if (_bankingTransactions.ContainsKey(id))
            {
                item = _bankingTransactions[id];
            }
            else
            {
                throw new Exception("Item does not exist.");
            }
            return(item.Clone());
        }
コード例 #3
0
        // check for the balanced portfolios
        // add 10% cash bonus
        public static void AddBounus(AppDbContext db)
        {
            // Get all of the stock account
            var SAQ = from sa in db.StockAccount
                      where sa.Trades.Count != 0 && sa.BankingTransaction.Count != 0 && sa.Balanced == true
                      select sa;

            List <StockAccount> AllStockAccounts = SAQ.ToList();

            foreach (StockAccount sa in AllStockAccounts)
            {
                // Calculate the value
                Decimal value = sa.CashBalance;
                value += sa.Gains;
                value += sa.StockBalance;

                // Calculate the 10% bonus
                Decimal Bonus = (value * 0.10m);

                // Add the Bonus value to the cash portion of the stocks
                sa.CashBalance += Bonus;

                // Update the Database and Save
                db.Entry(sa).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();

                // Create a new transaction for the bonus
                BankingTransaction BonusTransaction = new BankingTransaction
                {
                    BankingTransactionType = BankingTranactionType.Bonus,
                    Amount          = Bonus,
                    Description     = "Balanced Portfolio Bonus",
                    StockAccount    = sa,
                    TransactionDate = DateTime.Today,
                };

                // Add the transaction to the database and save the changes
                db.BankingTransaction.Add(BonusTransaction);
                db.SaveChanges();
            }
            ;
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "CheckingID, Balance, Name")] Checking checking)
        {
            Decimal originaldeposit = checking.Balance;
            var     CustomerQuery   = from c in db.Users
                                      where c.UserName == User.Identity.Name
                                      select c;

            AppUser customer = CustomerQuery.FirstOrDefault();

            if (customer == null)
            {
                return(HttpNotFound());
            }


            if (ModelState.IsValid)
            {
                // Auto incremement the number
                checking.AccountNumber = AccountNumber.AutoNumber(db);

                // change the name
                if (checking.Name == null)
                {
                    checking.Name = "Longhorn Checking";
                }

                // Associate the Customer with the checking account
                checking.Customer = customer;


                db.CheckingAccount.Add(checking);
                db.SaveChanges();

                // check to see if the deposit amount is over $5000
                ApprovedorNeedsApproval FirstDeposit;
                if (checking.Balance > 5000m)
                {
                    FirstDeposit = ApprovedorNeedsApproval.NeedsApproval;
                    //Added by Carson 5/2
                    checking.PendingBalance = checking.Balance;
                    checking.Balance        = 0;
                }
                else
                {
                    FirstDeposit = ApprovedorNeedsApproval.Approved;
                }
                var CheckingQuery = from ca in db.CheckingAccount
                                    where ca.AccountNumber == checking.AccountNumber
                                    select ca;

                Checking        CustomerCheckingAccount = CheckingQuery.FirstOrDefault();
                List <Checking> CustomerCheckingList    = new List <Checking>();
                CustomerCheckingList.Add(CustomerCheckingAccount);

                // Create a new transaction
                BankingTransaction InitialDeposit = new BankingTransaction
                {
                    Amount                 = originaldeposit,
                    ApprovalStatus         = FirstDeposit,
                    BankingTransactionType = BankingTranactionType.Deposit,
                    Description            = "Initial Deposit to Cash Balance",
                    TransactionDate        = DateTime.Today,
                    TransactionDispute     = DisputeStatus.NotDisputed,
                    CheckingAccount        = CustomerCheckingList
                };

                // Add the transaction to the database
                db.BankingTransaction.Add(InitialDeposit);
                db.SaveChanges();
                return(RedirectToAction("Portal", "Home", new { id = customer.Id }));
            }


            return(View(checking));
        }
コード例 #5
0
        /// <summary>
        ///     Adds operation to history of this account
        /// </summary>
        internal void AddOperation(BankingTransaction transaction)
        {
            //OperationHistory ??= new List<BankingTransaction>();

            //OperationHistory.Add(transaction);
        }
コード例 #6
0
 public int AddVendingTransaction(BankingTransaction item)
 {
     item.Id = _bankingTransactionId++;
     _bankingTransactions.Add(item.Id, item.Clone());
     return(item.Id);
 }
コード例 #7
0
 public void ProcessTransaction(BankingTransaction bt)
 {
     // Code not shown.
 }
コード例 #8
0
        public ActionResult SellStocks(SellStocksTrade Sale)
        {
            // Get the Customer
            // Query the Database for the logged in user
            var CustomerQuery = from c in db.Users
                                where c.UserName == User.Identity.Name
                                select c;
            // Get the Customer
            AppUser customer = CustomerQuery.FirstOrDefault();

            //Return frozen view if no go
            if (customer.ActiveStatus == false)
            {
                return(View("Frozen"));
            }

            // Get the original trade
            Trade OriginalTrade = db.Trades.Find(Sale.TradeID);

            // Get the Stock that is being sold
            StockMarket StockSale = db.StockMarket.Find(Sale.StockMarketID);

            // Get the Stock Account
            StockAccount CustomerStockAccount = db.StockAccount.Find(Sale.StockAccountID);

            // create a new transaction list for the trade
            List <BankingTransaction> TradeTrans = new List <BankingTransaction>();

            // Check the dates
            if (Sale.SaleDate < OriginalTrade.TransactionDate)
            {
                ViewBag.Error = "Cannot sell before purchase";
                return(View("SaleError"));
            }

            if (Sale.QuantitySold == 0)
            {
                ViewBag.Error = "Cannot sell with zero quantity";
                return(View("SaleError"));
            }

            // String for the description
            String Description = ($"Sale of {StockSale.CompanyName}, for {Sale.QuantitySold} shares, with initial price of {OriginalTrade.PricePerShare}, current price of {StockSale.StockPrice}, and a gain/loss of {Sale.Profit}");

            // Sale Amount
            Decimal SaleAmount = (Sale.QuantitySold * StockSale.StockPrice);

            // Create a new fee transaction and add it to the list
            BankingTransaction FeeTrans = new BankingTransaction
            {
                Amount = StockSale.Fee,
                BankingTransactionType = BankingTranactionType.Fee,
                Description            = ("Fee for sale of " + StockSale.CompanyName),
                StockAccount           = CustomerStockAccount,
                TransactionDate        = Sale.SaleDate,
                TransactionDispute     = DisputeStatus.NotDisputed
            };

            // Add the transaction to the list
            TradeTrans.Add(FeeTrans);

            // Make the trade happen
            Trade SaleTrade = new Trade()
            {
                TradeType           = TradeType.Sell,
                Amount              = (Sale.QuantitySold * StockSale.StockPrice),
                PricePerShare       = StockSale.StockPrice,
                Ticker              = StockSale.Ticker,
                Quantity            = Sale.QuantitySold,
                TransactionDate     = Sale.SaleDate,
                Description         = Description,
                StockMarket         = StockSale,
                StockAccount        = CustomerStockAccount,
                BankingTransactions = TradeTrans,
                TransactionDispute  = DisputeStatus.NotDisputed
            };

            // Create a new transaction for the actual sale
            BankingTransaction SaleTrans = new BankingTransaction
            {
                Amount = SaleAmount,
                BankingTransactionType = BankingTranactionType.Deposit,
                Description            = Description,
                StockAccount           = CustomerStockAccount,
                Trade              = SaleTrade,
                TransactionDate    = Sale.SaleDate,
                TransactionDispute = DisputeStatus.NotDisputed
            };

            // Add the transactions and the trades the the db
            db.BankingTransaction.Add(FeeTrans);
            db.SaveChanges();

            db.Trades.Add(SaleTrade);
            db.SaveChanges();

            db.BankingTransaction.Add(SaleTrans);
            db.SaveChanges();

            // Update the stock account

            // Take out the fee
            CustomerStockAccount.CashBalance -= Sale.Fee;

            // Add the fee to the account
            CustomerStockAccount.TradingFee += Sale.Fee;

            // Add/Subtract the profit
            CustomerStockAccount.CashBalance += Sale.Profit;

            // Update the Database
            db.Entry(CustomerStockAccount).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();


            // Remove the shares from the account

            // Check to see if there is any stock left
            // If there is no stock left then we need to remove the original buy trade
            if (OriginalTrade.Quantity - Sale.QuantitySold == 0)
            {
                // Clear the associated foriegn keys
                OriginalTrade.BankingTransactions.Clear();

                // Remove the original trade
                db.Trades.Remove(OriginalTrade);
            }

            // If the original trade quantity is not zero
            else
            {
                // update the quantity
                OriginalTrade.Quantity -= Sale.QuantitySold;

                // update the database
                db.Entry(OriginalTrade).State = System.Data.Entity.EntityState.Modified;
            }

            // Save the changes
            db.SaveChanges();

            // Check to see if the account is balanced
            BalancedPortfolio.CheckBalanced(db, customer);

            // Return users to the stock account details page
            return(RedirectToAction("Details", "StockAccounts"));
        }
コード例 #9
0
        public ActionResult PurchaseStocks(PurchaseStockTrade PurchcaseTrade)
        {
            try
            {
                // get the customer
                AppUser Customer = db.Users.Find(PurchcaseTrade.CustomerProfile.Id);

                if (Customer == null)
                {
                    return(RedirectToAction("Portal", "Home"));
                }

                if (PurchcaseTrade.TradeDate < DateTime.Today || PurchcaseTrade.TradeDate == null)
                {
                    ViewBag.Error = "Date cannot be before today";
                    return(View("PurchaseError"));
                }

                if (PurchcaseTrade.Quantity == 0)
                {
                    ViewBag.Error = "Quantity cannot be 0";
                    return(View("PurchaseError"));
                }
                // Get the stock
                StockMarket SelectedStock = db.StockMarket.Find(PurchcaseTrade.SelectedStock.StockMarketID);

                // Get the total amount
                Decimal decTotal = (PurchcaseTrade.Quantity * SelectedStock.StockPrice);

                // create a new transaction list for the trade
                List <BankingTransaction> TradeTrans = new List <BankingTransaction>();

                // Create a new fee transaction and add it to the list
                BankingTransaction FeeTrans = new BankingTransaction
                {
                    Amount = SelectedStock.Fee,
                    BankingTransactionType = BankingTranactionType.Fee,
                    Description            = ("Fee for purchase of " + SelectedStock.CompanyName),
                    TransactionDate        = (PurchcaseTrade.TradeDate),
                    StockAccount           = Customer.StockAccount.FirstOrDefault(),
                    TransactionDispute     = DisputeStatus.NotDisputed
                };

                TradeTrans.Add(FeeTrans);

                // Make the trade happen
                Trade Trade = new Trade()
                {
                    Amount              = decTotal,
                    Quantity            = PurchcaseTrade.Quantity,
                    Ticker              = SelectedStock.Ticker,
                    TransactionDate     = PurchcaseTrade.TradeDate,
                    PricePerShare       = SelectedStock.StockPrice,
                    TradeType           = TradeType.Buy,
                    StockAccount        = Customer.StockAccount.FirstOrDefault(),
                    StockMarket         = SelectedStock,
                    BankingTransactions = TradeTrans,
                    DisputeMessage      = "None",
                    TransactionDispute  = DisputeStatus.NotDisputed,
                    Description         = "None",
                    CorrectedAmount     = 0
                };

                // Get the customer Savings account
                var SAQ = from sa in db.StockAccount
                          where sa.Customer.Id == Customer.Id
                          select sa;

                StockAccount CustomerStockAccount = SAQ.FirstOrDefault();

                // check the account nulls
                if (PurchcaseTrade.CheckingAccounts != null)
                {
                    // find the account
                    Checking CustomerChecking = db.CheckingAccount.Find(PurchcaseTrade.CheckingAccounts.CheckingID);

                    if (CustomerChecking == null)
                    {
                        return(RedirectToAction("Portal", "Home"));
                    }

                    // take the money from the account
                    if (CustomerChecking.Balance - decTotal >= 0)
                    {
                        // Check to see if the cash balance is enough for the fee
                        if (db.StockAccount.Find(Customer.StockAccount.FirstOrDefault().StockAccountID).CashBalance < SelectedStock.Fee)
                        {
                            ViewBag.Error = "Fee was greater than Stock Cash Balance";
                            return(View("PurchaseError"));
                        }

                        // create a list to hold the checking account
                        List <Checking> CheckingList = new List <Checking>();
                        CheckingList.Add(CustomerChecking);

                        //Create a new transaction
                        BankingTransaction CheckingTrans = new BankingTransaction
                        {
                            Amount = decTotal,
                            BankingTransactionType = BankingTranactionType.Withdrawl,
                            CheckingAccount        = CheckingList,
                            Description            = ("Stock Purchase - Stock Account " + Customer.StockAccount.FirstOrDefault().AccountNumber.ToString()),
                            TransactionDate        = PurchcaseTrade.TradeDate,
                            Trade = Trade,
                            TransactionDispute = DisputeStatus.NotDisputed
                        };

                        // add the stuff to the database
                        db.BankingTransaction.Add(FeeTrans);
                        db.SaveChanges();

                        db.Trades.Add(Trade);
                        db.SaveChanges();

                        // Take the money out
                        db.CheckingAccount.Find(CustomerChecking.CheckingID).Balance -= decTotal;

                        // take out the fee
                        CustomerStockAccount.CashBalance -= SelectedStock.Fee;

                        // take out the fee
                        CustomerStockAccount.TradingFee += SelectedStock.Fee;

                        db.Entry(CustomerStockAccount).State = System.Data.Entity.EntityState.Modified;
                        db.BankingTransaction.Add(CheckingTrans);
                        db.SaveChanges();
                    }

                    // HACK
                    else
                    {
                        ViewBag.Error = "Not Enough Money in Account to Purchase the Stocks";
                        return(View("PurchaseError"));
                    }


                    // Any further changes
                }
                else if (PurchcaseTrade.SavingsAccount != null)
                {
                    // Get the customer Savings account
                    Saving CustomerSavings = db.SavingsAccount.Find(PurchcaseTrade.SavingsAccount.SavingID);

                    // take the money from the account
                    if (CustomerSavings.Balance - decTotal >= 0)
                    {
                        // Check to see if the cash balance is enough for the fee
                        if (db.StockAccount.Find(Customer.StockAccount.FirstOrDefault().StockAccountID).CashBalance < SelectedStock.Fee)
                        {
                            ViewBag.Error = "Fee was greater than Stock Cash Balance";
                            return(View("PurchaseError"));
                        }

                        // create a list to hold the checking account
                        List <Saving> SavingsList = new List <Saving>();
                        SavingsList.Add(CustomerSavings);

                        //Create a new transaction
                        BankingTransaction SavingsTrans = new BankingTransaction
                        {
                            Amount = decTotal,
                            BankingTransactionType = BankingTranactionType.Withdrawl,
                            SavingsAccount         = SavingsList,
                            Description            = ("Stock Purchase - Stock Account " + Customer.StockAccount.FirstOrDefault().AccountNumber.ToString()),
                            TransactionDate        = PurchcaseTrade.TradeDate,
                            Trade = Trade,
                            TransactionDispute = DisputeStatus.NotDisputed
                        };

                        // add the stuff to the database
                        db.BankingTransaction.Add(FeeTrans);
                        db.SaveChanges();

                        db.Trades.Add(Trade);
                        db.SaveChanges();

                        // Take the money out
                        db.SavingsAccount.Find(CustomerSavings.SavingID).Balance -= decTotal;

                        // take out the fee
                        CustomerStockAccount.CashBalance -= SelectedStock.Fee;

                        // take out the fee
                        CustomerStockAccount.TradingFee += SelectedStock.Fee;

                        db.Entry(CustomerStockAccount).State = System.Data.Entity.EntityState.Modified;
                        db.BankingTransaction.Add(SavingsTrans);
                        db.SaveChanges();
                    }

                    // HACK
                    else
                    {
                        ViewBag.Error = "Not Enough Money in Account to Purchase the Stocks";
                        return(View("PurchaseError"));
                    }
                }
                else if (PurchcaseTrade.AccountStock != null)
                {
                    // take the money from the account
                    if (CustomerStockAccount.CashBalance - decTotal >= 0)
                    {
                        // Check to see if the cash balance is enough for the fee
                        if (db.StockAccount.Find(Customer.StockAccount.FirstOrDefault().StockAccountID).CashBalance < SelectedStock.Fee)
                        {
                            ViewBag.Error = "Fee was greater than Stock Cash Balance";
                            return(View("PurchaseError"));
                        }

                        // create a list to hold the checking account
                        List <StockAccount> StockAccountList = new List <StockAccount>();
                        StockAccountList.Add(CustomerStockAccount);

                        //Create a new transaction
                        BankingTransaction StocksTrans = new BankingTransaction()
                        {
                            Amount = decTotal,
                            BankingTransactionType = BankingTranactionType.Withdrawl,
                            StockAccount           = CustomerStockAccount,
                            Description            = ("Stock Purchase - Stock Account " + Customer.StockAccount.FirstOrDefault().AccountNumber.ToString()),
                            TransactionDate        = PurchcaseTrade.TradeDate,
                            Trade = Trade,
                            TransactionDispute = DisputeStatus.NotDisputed
                        };

                        // add the stuff to the database
                        db.BankingTransaction.Add(FeeTrans);
                        db.SaveChanges();

                        db.Trades.Add(Trade);
                        db.SaveChanges();

                        // Take the money out
                        CustomerStockAccount.CashBalance -= decTotal;

                        // take out the fee
                        CustomerStockAccount.CashBalance -= SelectedStock.Fee;

                        // take out the fee
                        CustomerStockAccount.TradingFee += SelectedStock.Fee;

                        db.Entry(CustomerStockAccount).State = System.Data.Entity.EntityState.Modified;
                        db.BankingTransaction.Add(StocksTrans);
                        db.SaveChanges();
                    }

                    // HACK
                    else
                    {
                        ViewBag.Error = "Not Enough Money in Account to Purchase the Stocks";
                        return(View("PurchaseError"));
                    }
                }

                else
                {
                    return(HttpNotFound());
                }

                // Add the stuff to the database
                // check to see if the porfolio is balanced
                BalancedPortfolio.CheckBalanced(db, Customer);

                return(View("PurchaseConfirmation"));
            }
            catch (Exception e)
            {
                ViewBag.Error = "An unknown error occured";
                return(View("PurchaseError"));
            }
        }
コード例 #10
0
        public ActionResult Create([Bind(Include = "IRAID, Balance, Name")] IRA ira)
        {
            var CustomerQuery = from c in db.Users
                                where c.UserName == User.Identity.Name
                                select c;

            AppUser customer = CustomerQuery.FirstOrDefault();

            if (customer == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                ira.Customer = customer;

                ira.AccountNumber = Utility.AccountNumber.AutoNumber(db);

                if (ira.Name == null)
                {
                    ira.Name = "Longhorn IRA";
                }

                db.IRAAccount.Add(ira);
                db.SaveChanges();

                // check to see if the deposit amount is over $5000
                ApprovedorNeedsApproval FirstDeposit;

                var IRAQuery = from ia in db.IRAAccount
                               where ia.AccountNumber == ira.AccountNumber
                               select ia;
                IRA        CustomerIRAAccount = IRAQuery.FirstOrDefault();
                List <IRA> CustomerIRAList    = new List <IRA>();
                CustomerIRAList.Add(CustomerIRAAccount);
                if (ira.Balance > 5000m)
                {
                    IRA SelectedIra = db.IRAAccount.Find(CustomerIRAAccount.IRAID);
                    SelectedIra.Balance         = 0;
                    db.Entry(SelectedIra).State = EntityState.Modified;
                    db.SaveChanges();
                    ira.Balance      = 0;
                    ira.RunningTotal = 0;
                    return(RedirectToAction("IRAError", "bankingTransactions", new { Description = "Initial Deposit to Cash Balance", Date = DateTime.Today, Amount = 0, IRAID = SelectedIra.IRAID, CID = 0, SID = 0, StAID = 0, btID = 0, type = BankingTranactionType.Deposit }));
                }

                else
                {
                    FirstDeposit = ApprovedorNeedsApproval.Approved;
                    // Create a new transaction
                }
                ira.RunningTotal = ira.Balance;

                BankingTransaction InitialDeposit = new BankingTransaction
                {
                    Amount                 = ira.Balance,
                    ApprovalStatus         = FirstDeposit,
                    BankingTransactionType = BankingTranactionType.Deposit,
                    Description            = "Initial Deposit to Cash Balance",
                    TransactionDate        = DateTime.Today,
                    TransactionDispute     = DisputeStatus.NotDisputed,
                    IRAAccount             = CustomerIRAList
                };

                // Add the transaction to the database
                db.BankingTransaction.Add(InitialDeposit);
                db.SaveChanges();

                return(RedirectToAction("Portal", "Home", new { id = customer.Id }));
            }

            return(View(ira));
        }
コード例 #11
0
        public ActionResult PayBillsPage(PayeeViewModel Pay)
        {
            // get the customer
            AppUser Customer = db.Users.Find(Pay.UserCustomerProfile.Id);

            if (Customer == null)
            {
                return(RedirectToAction("Portal", "Home"));
            }

            // create a new transaction list for the trade
            List <BankingTransaction> PayeeTrans = new List <BankingTransaction>();

            Checking CustomerChecking = db.CheckingAccount.Find(Pay.CheckingID);

            Saving CustomerSaving = db.SavingsAccount.Find(Pay.SavingID);

            if (CustomerChecking == null && CustomerSaving == null)
            {
                return(RedirectToAction("Portal", "Home"));
            }

            if (CustomerChecking != null)
            {
                if (CustomerChecking.Balance >= 0)
                {
                    List <Checking> CheckingList = new List <Checking>();

                    CheckingList.Add(CustomerChecking);

                    if (CustomerChecking.Balance - Pay.PayeeTransaction.Amount >= -50)
                    {
                        if (CustomerChecking.Balance - Pay.PayeeTransaction.Amount < 0 && CustomerChecking.Balance - Pay.PayeeTransaction.Amount >= -50)
                        {
                            BankingTransaction OverDrawn = new BankingTransaction
                            {
                                Amount = 30,
                                BankingTransactionType = BankingTranactionType.Fee,
                                TransactionDate        = Pay.PayeeTransaction.TransactionDate,
                                CheckingAccount        = CheckingList,
                                ApprovalStatus         = ApprovedorNeedsApproval.Approved,
                                TransactionDispute     = DisputeStatus.NotDisputed,
                                Description            = "Over draw"
                            };

                            CustomerChecking.Overdrawn = true;

                            PayeeTrans.Add(OverDrawn);

                            db.BankingTransaction.Add(OverDrawn);

                            db.SaveChanges();

                            // Send the email
                            String Body = CustomerChecking.Name.ToString() + " : has been overdrawn and you have been charged a $30 fee. Your current account balance is $" + CustomerChecking.Balance.ToString();
                            LonghornBank.Utility.Email.PasswordEmail(Customer.Email, "Overdrawn Account", Body);
                        }

                        BankingTransaction CheckingWithdrawl = new BankingTransaction
                        {
                            Amount = Pay.PayeeTransaction.Amount,
                            BankingTransactionType = BankingTranactionType.BillPayment,
                            TransactionDate        = Pay.PayeeTransaction.TransactionDate,
                            CheckingAccount        = CheckingList,
                            Description            = Pay.PayeeTransaction.Description,
                            ApprovalStatus         = ApprovedorNeedsApproval.Approved,
                            TransactionDispute     = DisputeStatus.NotDisputed
                        };

                        db.CheckingAccount.Find(CustomerChecking.CheckingID).Balance -= Pay.PayeeTransaction.Amount;

                        db.BankingTransaction.Add(CheckingWithdrawl);
                        db.SaveChanges();
                    }

                    else
                    {
                        return(View("WithDrawalError"));
                    }
                }

                else
                {
                    return(View("BalanceError"));
                }
            }

            if (CustomerSaving != null)
            {
                if (CustomerSaving.Balance >= 0)
                {
                    List <Saving> SavingList = new List <Saving>();

                    SavingList.Add(CustomerSaving);

                    if (CustomerSaving.Balance - Pay.PayeeTransaction.Amount >= -50)
                    {
                        if (CustomerSaving.Balance - Pay.PayeeTransaction.Amount < 0 && CustomerSaving.Balance - Pay.PayeeTransaction.Amount >= -50)
                        {
                            BankingTransaction OverDrawn = new BankingTransaction
                            {
                                Amount = 30,
                                BankingTransactionType = BankingTranactionType.Fee,
                                TransactionDate        = Pay.PayeeTransaction.TransactionDate,
                                SavingsAccount         = SavingList,
                                TransactionDispute     = DisputeStatus.NotDisputed,
                                ApprovalStatus         = ApprovedorNeedsApproval.Approved,
                                Description            = "Over draw"
                            };

                            CustomerSaving.Overdrawn = true;

                            PayeeTrans.Add(OverDrawn);

                            db.BankingTransaction.Add(OverDrawn);
                            db.SaveChanges();

                            // Send the email
                            String Body = CustomerSaving.Name.ToString() + " : has been overdrawn and you have been charged a $30 fee. Your current account balance is $" + CustomerSaving.Balance.ToString();
                            LonghornBank.Utility.Email.PasswordEmail(Customer.Email, "Overdrawn Account", Body);
                        }

                        BankingTransaction CheckingWithdrawl = new BankingTransaction
                        {
                            Amount = Pay.PayeeTransaction.Amount,
                            BankingTransactionType = BankingTranactionType.BillPayment,
                            TransactionDate        = Pay.PayeeTransaction.TransactionDate,
                            SavingsAccount         = SavingList,
                            Description            = "Payment of bill",
                            ApprovalStatus         = ApprovedorNeedsApproval.Approved,
                            TransactionDispute     = DisputeStatus.NotDisputed
                        };

                        db.SavingsAccount.Find(CustomerSaving.SavingID).Balance -= Pay.PayeeTransaction.Amount;

                        db.BankingTransaction.Add(CheckingWithdrawl);
                        db.SaveChanges();
                    }

                    else
                    {
                        return(View("WithDrawalError"));
                    }
                }

                else
                {
                    return(View("BalanceError"));
                }
            }

            return(View("SuccessfulPayee"));
        }
コード例 #12
0
        public ActionResult Create([Bind(Include = "SavingID, Balance, Name")] Saving saving)
        {
            // Query the Customer
            var CustomerQuery = from c in db.Users
                                where c.UserName == User.Identity.Name
                                select c;

            AppUser customer = CustomerQuery.FirstOrDefault();

            int new_account_number = Convert.ToInt32(db.SavingsAccount.Count()) + 1000000000;

            if (customer == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                saving.Customer = customer;

                // Auto incremenment the account number
                saving.AccountNumber = Utility.AccountNumber.AutoNumber(db);

                if (saving.Name == null)
                {
                    saving.Name = "Longhorn Savings";
                }

                db.SavingsAccount.Add(saving);
                db.SaveChanges();

                // check to see if the deposit amount is over $5000
                ApprovedorNeedsApproval FirstDeposit;
                if (saving.Balance > 5000m)
                {
                    FirstDeposit = ApprovedorNeedsApproval.NeedsApproval;
                    //Added by Carson 5/2
                    saving.PendingBalance = saving.Balance;
                    saving.Balance        = 0;
                }
                else
                {
                    FirstDeposit = ApprovedorNeedsApproval.Approved;
                }
                var SavingQuery = from sa in db.SavingsAccount
                                  where sa.AccountNumber == saving.AccountNumber
                                  select sa;

                Saving        CustomerSavingAccount = SavingQuery.FirstOrDefault();
                List <Saving> CustomerSavingList    = new List <Saving>();
                CustomerSavingList.Add(CustomerSavingAccount);

                // Create a new transaction
                BankingTransaction InitialDeposit = new BankingTransaction
                {
                    Amount                 = saving.Balance,
                    ApprovalStatus         = FirstDeposit,
                    BankingTransactionType = BankingTranactionType.Deposit,
                    Description            = "Initial Deposit to Cash Balance",
                    TransactionDate        = DateTime.Today,
                    TransactionDispute     = DisputeStatus.NotDisputed,
                    SavingsAccount         = CustomerSavingList
                };

                // Add the transaction to the database
                db.BankingTransaction.Add(InitialDeposit);
                db.SaveChanges();
                return(RedirectToAction("Portal", "Home"));
            }

            return(View(saving));
        }