public static async Task <OrderResponse> PlaceOrder(Order order)
        {
            await TokenValidator.CheckTokenValidity();

            using (HttpClient httpClient = new HttpClient())
            {
                var token = Preferences.Get("access_token", string.Empty);
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);

                var json = JsonConvert.SerializeObject(order);
                using (StringContent content = new StringContent(json, Encoding.UTF8, "application/json"))
                {
                    var response = await httpClient.PostAsync(string.Format("{0}{1}", new object[] { AppSettings.API_URL, "Orders" }), content);

                    try
                    {
                        var jsonResult = await response.Content.ReadAsStringAsync();

                        return(JsonConvert.DeserializeObject <OrderResponse>(jsonResult));
                    }
                    catch (System.Exception ex)
                    {
                        throw ex;
                    }
                }
            }
        }
        public static async Task <Product> GetProductById(int productId)
        {
            await TokenValidator.CheckTokenValidity();

            using (HttpClient httpClient = new HttpClient())
            {
                var token = Preferences.Get("access_token", string.Empty);
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);

                var response = await httpClient.GetStringAsync(string.Format("{0}{1}/{2}", new object[] { AppSettings.API_URL, "Products", productId }));

                return(JsonConvert.DeserializeObject <Product>(response));
            }
        }
        public static async Task <bool> ClearShoppingCart(int userId)
        {
            await TokenValidator.CheckTokenValidity();

            using (HttpClient httpClient = new HttpClient())
            {
                var token = Preferences.Get("access_token", string.Empty);
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);

                var response = await httpClient.DeleteAsync(string.Format("{0}{1}/{2}", new object[] { AppSettings.API_URL, "ShoppingCartItems", userId }));

                if (!response.IsSuccessStatusCode)
                {
                    return(false);
                }

                return(true);
            }
        }
        public static async Task <bool> AddItemsToCart(AddToCart addToCart)
        {
            await TokenValidator.CheckTokenValidity();

            using (HttpClient httpClient = new HttpClient())
            {
                var token = Preferences.Get("access_token", string.Empty);
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token);

                var json = JsonConvert.SerializeObject(addToCart);
                using (StringContent content = new StringContent(json, Encoding.UTF8, "application/json"))
                {
                    var response = await httpClient.PostAsync(string.Format("{0}{1}", new object[] { AppSettings.API_URL, "ShoppingCartItems" }), content);

                    if (!response.IsSuccessStatusCode)
                    {
                        return(false);
                    }

                    return(true);
                }
            }
        }