Example #1
0
        // Creates a new client user
        public ActionResult CreateClient()
        {
            // Ensures logged in
            if (Session["loggedInState"] == null)
            {
                return Redirect("/403.html");
            }

            // Checks if logged in
            bool state = (bool)Session["loggedInState"];
            if (state == true)
            {
                // Establishes models
                ClientUserModel cModel = new ClientUserModel();

                // Establishes handlers
                AccountHandler accHand = new AccountHandler();
                AddressHandler addHand = new AddressHandler();
                BankHandler banHand = new BankHandler();
                ContactHandler conHand = new ContactHandler();
                CustomerHandler cusHand = new CustomerHandler();

                // Extract for account details
                int accountType = int.Parse(Request.Form["accountTypes"]);

                // Extract for bank details
                String sortCode = Request.Form["sortCode"];
                int accountNumber = int.Parse(Request.Form["accountNumber"]);

                // Extract for client details
                String username = Request.Form["username"];
                String password = Request.Form["password1"];
                String name = Request.Form["clientName"];

                // Extract contact details
                String forename = Request.Form["contactForename"];
                String surname = Request.Form["contactSurname"];
                String position = Request.Form["contactPosition"];
                String phoneNumber = Request.Form["contactPhone"];

                // Extract bank address details
                //String blineOne = Request.Form["bankL1"];
                //String blineTwo = Request.Form["bankL2"]; ;
                //String blineThree = Request.Form["bankL3"];
                //String blineFour = Request.Form["bankL4"];
                //String blineFive = Request.Form["bankL5"];
                //String bcState = Request.Form["bankState"];
                //String bcounty = Request.Form["bankCounty"];
                //String bcountry = Request.Form["bankCountry"];
                //String bpostalCode = Request.Form["bankPostalCode"];

                // Extract for customer details
                String compName = Request.Form["clientName"];

                // Extract customer address details
                String clineOne = Request.Form["address1"];
                String clineTwo = Request.Form["address2"]; ;
                String clineThree = Request.Form["address3"];
                String clineFour = Request.Form["address4"];
                String clineFive = Request.Form["address5"];
                String ccState = Request.Form["state"];
                String ccounty = Request.Form["county"];
                String ccountry = Request.Form["country"];
                String cpostalCode = Request.Form["postcode"];

                // Creates objects for user
                //int bankAddressID = addHand.create(blineOne, blineTwo, blineThree, blineFour, blineFive, bcState,
                //                                   bcounty, bcountry, bpostalCode);
                int custAddressID = addHand.create(clineOne, clineTwo, clineThree, clineFour, clineFive, ccState,
                                                   ccounty, ccountry, cpostalCode);
                int bankID = banHand.create(sortCode, accountNumber);
                int contactID = conHand.create(forename, surname, position, phoneNumber);
                int customerID = cusHand.create(compName, custAddressID);
                int accountID = accHand.create(accountType, bankID, customerID, contactID);

                // Holds new objects
                ClientUser newClient = new ClientUser();

                // Acquires needed Account ID
                newClient.Username = username;

                // Stored details for the customer
                newClient.Name = name;
                newClient.Username = username;
                newClient.Password = password;
                newClient.AccountID = accountID;

                // Creates the customer
                int clientID = cModel.CreateClientUser(newClient);

                // Return created department to view
                return Redirect("/Index/adminIndex");
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }