/// <summary>Gets all of the Stores for the group.</summary>
        /// <exception cref="Exception">Thrown when the call is not successful.</exception>
        /// <returns>A collection of all Stores for the group.</returns>
        public List <Store> GetAll()
        {
            CallResults results = AJAX.CallAPI(STORES_API_URL, Constants.enumRESTVerb.GET);

            if (!results.Success)
            {
                throw new Exception($"Error {System.Reflection.MethodBase.GetCurrentMethod().Name} - the error is {results.ErrorMessage}");
            }

            List <Store> stores = JsonConvert.DeserializeObject <List <Store> >(results.Json);

            return(stores);
        }
Example #2
0
        /// <summary>Creates a new CustomerOrder through the API</summary>
        /// <exception cref="Exception">Thrown when the call is not successful.</exception>
        /// <param name="newOrder">NewCustomerOrder instance to create order from.</param>
        /// <returns>The uid of the newly created CustomerOrder.</returns>
        public int Create(NewCustomerOrder newOrder)
        {
            string json = JsonConvert.SerializeObject(newOrder);

            CallResults results = AJAX.CallAPI(CUSTOMERORDER_API_URL, Constants.enumRESTVerb.POST, json);

            if (!results.Success || !int.TryParse(results.Json, out int orderId))
            {
                throw new Exception($"Error {MethodBase.GetCurrentMethod().Name} - the error is {results.ErrorMessage}");
            }

            return(orderId);
        }
Example #3
0
        /// <summary>Gets a customer order based on passed order id.</summary>
        /// <exception cref="Exception">Thrown when the call is not successful.</exception>
        /// <param name="orderId">Id of the order to get.</param>
        /// <returns>The CustomerOrder.</returns>
        public CustomerOrder GetByOrderId(int orderId)
        {
            CallResults results = AJAX.CallAPI($"{CUSTOMERORDER_API_URL}{orderId}", Constants.enumRESTVerb.GET);

            if (!results.Success)
            {
                throw new Exception($"Error {MethodBase.GetCurrentMethod().Name} - the error is {results.ErrorMessage}");
            }

            CustomerOrder order = JsonConvert.DeserializeObject <CustomerOrder>(results.Json);

            return(order);
        }
Example #4
0
        /// <summary>Gets all headers.Gets all of the orders but does not include line items.</summary>
        /// <exception cref="Exception">Thrown when the call is not successful.</exception>
        /// <returns>List of Customer Orders.</returns>
        public List <CustomerOrder> GetAllHeaders()
        {
            CallResults results = AJAX.CallAPI(CUSTOMERORDER_API_URL, Constants.enumRESTVerb.GET);

            if (!results.Success)
            {
                throw new Exception($"Error {MethodBase.GetCurrentMethod().Name} - the error is {results.ErrorMessage}");
            }

            List <CustomerOrder> customerOrders = JsonConvert.DeserializeObject <List <CustomerOrder> >(results.Json);

            return(customerOrders);
        }
Example #5
0
        /// <summary>Saves the passed Customer through the API</summary>
        /// <exception cref="Exception">Thrown when the call is not successful.</exception>
        /// <param name="customerToSave">The Customer to save.</param>
        /// <returns>True if it succeeds, false if it fails.</returns>
        public bool Save(Customer customerToSave)
        {
            string json = JsonConvert.SerializeObject(customerToSave);

            CallResults results = AJAX.CallAPI(CUSTOMER_API_URL, Constants.enumRESTVerb.PUT, json);

            if (!results.Success)
            {
                throw new Exception($"Error {System.Reflection.MethodBase.GetCurrentMethod().Name} - the error is {results.ErrorMessage}");
            }

            return(results.Success);
        }
Example #6
0
        /// <summary>Gets a Customer through the API based on the passed email address.</summary>
        /// <exception cref="Exception">Thrown when the call is not successful.</exception>
        /// <param name="email">The email of the customer to get.</param>
        /// <returns>The Customer.</returns>
        public Customer GetByEmail(string email)
        {
            //Email needs to be formatted correctly for the call to work. Replace @ with
            // %40 and add a trailing '/'.
            string formattedEmail = $"{email.Replace("@", "%40")}/";

            CallResults results = AJAX.CallAPI($"{CUSTOMER_API_URL}{formattedEmail}", Constants.enumRESTVerb.GET);

            if (!results.Success)
            {
                throw new Exception($"Error {System.Reflection.MethodBase.GetCurrentMethod().Name} - the error is {results.ErrorMessage}");
            }

            Customer customer = JsonConvert.DeserializeObject <Customer>(results.Json);

            return(customer);
        }