Example #1
0
        public ActionResult loginpost()
        {
            LoginModel loginModel = new LoginModel();
            ClientUserModel clientmModel = new ClientUserModel();

            // To store login details
            String username;
            String password;

            // Acquire login details from front-end
            username = Request.Form[0];
            password = Request.Form[1];

            // Composes object
            User thisUser = new User();
            thisUser.username = username;
            thisUser.password = password;
            ClientUser client = new ClientUser();
            client.Username = username;
            client.Password = password;

            // get Account Type / Access levels from Database
            LoggedIn logState;
            logState = loginModel.Login(thisUser);

            if (logState.State)
            {
                Session["loggedInState"] = logState.State;
                Session["username"] = thisUser.username;
                Session["userID"] = logState.UserID;
                Session["Type"] = "Employee";
            }
            else
            {
                logState = clientmModel.Login(client);

                Session["loggedInState"] = logState.State;
                Session["username"] = client.Username;
                Session["userID"] = logState.UserID;
                Session["Type"] = "Client";
            }

            // Sets the Session variables

            // Acquire type of user from Ryan
            // Redirect based on user:
                // Admin (Staff)
                // User (Client)

            // variable to store the path to redirect to
            String pageToDirectTo = "/index.html";

            try {
                bool state = (bool)Session["loggedInState"];
                if (state == true)
                {
                    if (Session["Type"].ToString() == "Employee")
                    {
                        pageToDirectTo = "/Index/";
                        if (logState.AccessLevel.Equals("Admin"))
                        {
                            pageToDirectTo = "/Index/adminIndex";
                        }
                    }
                    else
                    {
                        pageToDirectTo = "/Index/clientIndex"; // doesn't work
                    }
                }
                else
                {
                    pageToDirectTo = "/login.html";
                }
            }catch(Exception e){
                pageToDirectTo = "/403.html";
            }

            // redirect the user to the relevant page
            return Redirect(pageToDirectTo);
        }
Example #2
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");
            }
        }
Example #3
0
        // 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");
            }
        }