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)); }
public ActionResult Create([Bind(Include = "StockAccountID,Name")] StockAccount stockAccount) { if (ModelState.IsValid) { // 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(); //Change field to needs approval stockAccount.ApprovalStatus = ApprovedorNeedsApproval.NeedsApproval; if (customer == null) { return(HttpNotFound()); } // Add relate the stock account to the customer stockAccount.Customer = customer; // Get the account number stockAccount.AccountNumber = AccountNumber.AutoNumber(db); if (stockAccount.Name == null) { stockAccount.Name = "Longhorn Stock Portfolio"; } // set the stock account to needs approval stockAccount.ApprovalStatus = ApprovedorNeedsApproval.NeedsApproval; stockAccount.CashBalance = 0m; stockAccount.PendingBalance = 0m; stockAccount.Balanced = false; db.StockAccount.Add(stockAccount); db.SaveChanges(); /* Add the inital deposit to the account * * // Get the StockAccount * var StockAccountQuery = from sa in db.StockAccount * where sa.Customer.Id == customer.Id * select sa; * * StockAccount CustomerStockAccount = StockAccountQuery.FirstOrDefault(); * * // check to see if the deposit amount is over $5000 * ApprovedorNeedsApproval FirstDeposit; * if (stockAccount.CashBalance > 5000m) * { * FirstDeposit = ApprovedorNeedsApproval.NeedsApproval; * } * else * { * FirstDeposit = ApprovedorNeedsApproval.Approved; * } * * // Create a new transaction * BankingTransaction InitialDeposit = new BankingTransaction * { * Amount = stockAccount.CashBalance, * ApprovalStatus = FirstDeposit, * BankingTransactionType = BankingTranactionType.Deposit, * Description = "Initial Deposit to Cash Balance", * TransactionDate = DateTime.Today, * TransactionDispute = DisputeStatus.NotDisputed, * StockAccount = CustomerStockAccount * }; * * * // Add the transaction to the database * db.BankingTransaction.Add(InitialDeposit); * db.SaveChanges(); * */ return(View("AccountConfirmation")); } return(View(stockAccount)); }