示例#1
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"));
            }
        }