/// <summary>
        /// This uploads a new quantity to the database
        /// </summary>
        /// <param name="product">The product to change</param>
        /// <param name="newQuantity">The new quantity</param>
        /// <returns></returns>
        public async static Task <bool> UploadChanges(Product product, int newQuantity)
        {
            product.stockCount = newQuantity;
            if (isDebug)
            {
                return(true);
            }
            else
            {
                try
                {
                    var listToSend = new List <KeyValuePair <string, string> >()
                    {
                        new KeyValuePair <string, string>("PRODUCT", product.ID.ToString()),
                        new KeyValuePair <string, string>("NEWQUANTITY", newQuantity.ToString())
                    };
                    string serverResponse = await MiddlewareHTTPClient.SendQuery("changeProductQuantity.jsp", listToSend);

                    return(serverResponse.Contains("SUCCESS"));
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
        /// <summary>
        /// This searches the database for a particular item, based on their search terms
        /// </summary>
        /// <param name="searchTerms"></param>
        /// <returns></returns>
        public async static Task <List <Product> > SearchForProduct(string searchTerms)
        {
            searchTerms = searchTerms.ToLower();
            if (isDebug)
            {
                return(DummyData.GetProdutcs().Where(xProduct => xProduct.name.ToLower().Contains(searchTerms)).ToList());
            }
            else
            {
                var listToSend = new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("TERM", searchTerms)
                };
                string serverResponse = await MiddlewareHTTPClient.SendQuery("searchProducts.jsp", listToSend);

                return(Newtonsoft.Json.JsonConvert.DeserializeObject <List <Product> >(serverResponse));
            }
        }
        /// <summary>
        /// Fulfills an order
        /// </summary>
        /// <param name="orderToFulfil">The order to fulfill</param>
        /// <returns></returns>
        public async static Task <bool> FulfillOrder(Order orderToFulfil)
        {
            if (isDebug)
            {
                return(true);
            }
            else
            {
                try
                {
                    var listToSend = new List <KeyValuePair <string, string> >()
                    {
                        new KeyValuePair <string, string>("ORDER", orderToFulfil.ID.ToString())
                    };
                    string serverResponse = await MiddlewareHTTPClient.SendQuery("fulfillOrder.jsp", listToSend);

                    return(serverResponse.Contains("SUCCESS"));
                } catch (Exception ex)
                {
                    return(false);
                }
            }
        }
        /// <summary>
        /// Returns a User based on their username. This won't return any of their passwords or personal information
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public async static Task <User> GetUser(string username)
        {
            if (isDebug)
            {
                return(new User()
                {
                    ID = 1,
                    authenticated = true,
                    contact = "5",
                    password = "",
                    username = "******"
                });
            }
            else
            {
                var listToSend = new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("ID", username)
                };
                string serverResponse = await MiddlewareHTTPClient.SendQuery("getUser.jsp", listToSend);

                return(Newtonsoft.Json.JsonConvert.DeserializeObject <User>(serverResponse));
            }
        }
        /// <summary>
        /// Returns a list of outstanding orders (unfulfilled orders)
        /// </summary>
        /// <returns></returns>
        public async static Task <List <Order> > GetOutstandingOrders()
        {
            if (isDebug)
            {
                // Return dummy data
                return(DummyData.GetOrders());
            }
            else
            {
                // Connect to the middleware
                List <Order> orderList;
                try
                {
                    string serverResponse = await MiddlewareHTTPClient.SendQuery("getUnfulfilled.jsp", new List <KeyValuePair <string, string> >());

                    // If null return an empty list or if data is contained then return the deserialized data
                    orderList = serverResponse == null ? new List <Order>() : Newtonsoft.Json.JsonConvert.DeserializeObject <List <Order> >(serverResponse);
                } catch (Exception)
                {
                    throw new Exception("Error Communicating With The Server");
                }
                return(orderList);
            }
        }