Exemplo n.º 1
0
        // This may be broken
        public int CreateOrder(Order o)
        {
            int ret = 0;
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {
                    try
                    {
                        string query = "NewOrder";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("OrderStatus", o.OrderStatus);
                        cmd.Parameters.AddWithValue("DatePlaced", o.Placed);
                        cmd.Parameters.AddWithValue("DateReceived", o.Received);
                        cmd.Parameters.AddWithValue("DateDelivered", o.Delivered);
                        cmd.Parameters.AddWithValue("GoodsID", o.GoodsID);
                        cmd.Parameters.AddWithValue("DestinationAddressID", o.DestinationAddressID);
                        cmd.Parameters.AddWithValue("SourceAddressID", o.SourceAddressID);
                        cmd.Parameters.AddWithValue("TotalCost", o.TotalCost);
                        cmd.Parameters.AddWithValue("AccountID", o.AccountID);
                        cmd.Parameters.AddWithValue("DesiredDeliveryDate", o.DesiredDeliveryDate);

                        ret = int.Parse(cmd.ExecuteScalar().ToString());

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
            return ret;
        }
Exemplo n.º 2
0
 // Calls the main method to get order.
 public Order SearchOrder(Order p)
 {
     return SearchOrder(p.ID);
 }
Exemplo n.º 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");
            }
        }
Exemplo n.º 4
0
        // This is the main method to get a order from the order ID within the databse.
        public Order SearchOrder(int ID)
        {
            var o = new Order();
            using (connect = new MySqlConnection(_connectionString))
            {
                try
                {
                    string query = "GetOrder";
                    var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                    cmd.Parameters.AddWithValue("OrderID", ID);

                    connect.Open();

                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        o.AccountID = int.Parse(reader["Purchase_ID"].ToString());
                        o.OrderStatus = reader["Order_Status"].ToString();
                        o.Placed = DateTime.Parse(reader["Date_Placed"].ToString());
                        o.Received = DateTime.Parse(reader["Date_Received"].ToString());
                        o.Delivered = DateTime.Parse(reader["Date_Delivered"].ToString());
                        o.TotalCost = Decimal.Parse(reader["Total_Cost"].ToString());
                        o.GoodsID = int.Parse(reader["Goods_ID"].ToString());
                        o.DestinationAddressID = int.Parse(reader["Destination_Address"].ToString());
                        o.SourceAddressID = int.Parse(reader["Source_Address"].ToString());
                        o.AccountID = int.Parse(reader["Account_ID"].ToString());
                        o.DesiredDeliveryDate = DateTime.Parse(reader["Desired_Delivery_Date"].ToString());

                    }

                    connect.Close();
                }
                catch (InvalidOperationException ioException)
                {
                    connect.Close();
                }

            }

            return o;
        }
Exemplo n.º 5
0
 // Gets a list of account by values specified in the package object.
 public List<Account> SearchAccounts(Order o)
 {
     throw new NotImplementedException();
 }