// Creates an account public int create(int accountTypeID, int bankID, int customerID, int contactID) { // Establishes model AccountModel accountModel = new AccountModel(); // Holds the new account Account newAccount = new Account(); Account_Type accountType = new Account_Type(); Bank newBank = new Bank(); // Stored details for the account newAccount.CustomerID = customerID; newAccount.ContactID = contactID; newAccount.AccountTypeID = accountTypeID; newAccount.BankID = bankID; // Creates the account int accountID = accountModel.CreateAccount(newAccount); // Returns accountID return accountID; }
// View individual customer details public ActionResult view() { // Null handling if (Session["loggedInState"] == null) { return Redirect("/403.html"); } // If logged in bool state = (bool)Session["loggedInState"]; if (state == true) { // Establishes models AccountModel clientModel = new AccountModel(); CustomerModel customerModel = new CustomerModel(); List<Account> accountList = new List<Account>(); // Get the ID requested int theID = int.Parse(Url.RequestContext.RouteData.Values["id"].ToString()); Customer customer = new Customer(); customer.ID = theID; accountList = clientModel.SearchAccounts(customer); foreach(var account in accountList) { account.Customer = customerModel.SearchCustomers(account.CustomerID); } return View(accountList); } else { // If not logged in return Redirect("/login.html"); } }
// GET: Order public ActionResult createOrder() { // Null handling if (Session["loggedInState"] == null) { return Redirect("/403.html"); } // Checks if logged in bool state = (bool)Session["loggedInState"]; if (state == true) { // Creates handlers for order creating GoodsHandler goodsHand = new GoodsHandler(); SpecificationHandler specHand = new SpecificationHandler(); PackageHandler packHand = new PackageHandler(); TransactionHandler tranHandler = new TransactionHandler(); // Necessary models ClientUserModel cuModel = new ClientUserModel(); OrderModel orderModel = new OrderModel(); // Stored details for package specification int weight = int.Parse(Request.Form["weight"]); int height = int.Parse(Request.Form["height"]); int length = int.Parse(Request.Form["length"]); int width = int.Parse(Request.Form["width"]); // Stored details for package String name = Request.Form["goodsDescriptor"]; String handling = Request.Form["options"]; String deliveryType = Request.Form["deliveryBands"]; // Stored details for order int deliveryBand = 0; switch (deliveryType) { case "Next Day Delivery": deliveryBand = 1; break; case "Express 1-2 Days": deliveryBand = 2; break; case "Standard 3-5 Days": deliveryBand = 3; break; case "Basic 5-10 Days": deliveryBand = 4; break; } // Holds the order objects Order newOrder = new Order(); // Creates the foreign objects, and gets the IDs int goodsID = goodsHand.create(name, handling); int specID = specHand.create(weight, height, length, width); int packID = packHand.create(goodsID, specID); // Acquires client data ClientUser thisUser = cuModel.SearchClientUser(int.Parse(Session["userID"].ToString())); // Acquires account type (Standard | Premium) AccountModel accModel = new AccountModel(); Account thisAccount = accModel.SearchAccount(thisUser.AccountID); int accountType = thisAccount.AccountTypeID; // Sets up the order newOrder.AccountID = thisUser.AccountID; newOrder.DestinationAddressID = int.Parse(Request.Form["address1"]); newOrder.SourceAddressID = int.Parse(Request.Form["address2"]); newOrder.Placed = DateTime.Now; newOrder.OrderStatus = "Placed"; newOrder.GoodsID = goodsID; // Calculate desired delivery date newOrder.DesiredDeliveryDate = calcDesiredDeliveryDate(deliveryBand, newOrder.Placed); // Price of order PackageModel packageModel = new PackageModel(); Package thisPackage = packageModel.SearchPackage(packID); int totalPrice = calcPrice(accountType, deliveryBand, thisPackage); // Creates the order int orderID = orderModel.CreateOrder(newOrder); // Sets up a transaction tranHandler.create(orderID, thisAccount.CustomerID, thisAccount.BankID); // Passes back to the view return Redirect("/Transaction/transactions"); } else { // If not logged in return Redirect("/login.html"); } }