Example #1
0
        public static async Task <List <ProductByCategory> > GetProductByCategory(int categoryID)
        {
            await TokenValidator.CheckToken();

            using (HttpClient httpClient = new HttpClient()) {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));
                var response = await httpClient.GetStringAsync($"{AppSettings.APIURL}api/Products/ProductsByCategory/{categoryID}");

                return(JsonConvert.DeserializeObject <List <ProductByCategory> >(response));
            }
        }
Example #2
0
        public static async Task <List <Order> > GetOrderDettails(int orderId)
        {
            await TokenValidator.CheckToken();

            using (HttpClient httpClient = new HttpClient()) {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));
                var response = await httpClient.GetStringAsync($"{AppSettings.APIURL}api/Orders/OrderDetails/{orderId}");

                return(JsonConvert.DeserializeObject <List <Order> >(response));
            }
        }
Example #3
0
        public static async Task <TotalCartItems> GetTotalCartItems(int userID)
        {
            await TokenValidator.CheckToken();

            using (HttpClient httpClient = new HttpClient()) {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));
                var response = await httpClient.GetStringAsync($"{AppSettings.APIURL}api/ShoppingCartItems/TotalItems/{userID}");

                return(JsonConvert.DeserializeObject <TotalCartItems>(response));
            }
        }
Example #4
0
        public static async Task <OrderResponce> PlceOrder(Order order)
        {
            await TokenValidator.CheckToken();

            using (HttpClient httpClient = new HttpClient()) {
                var userJson = JsonConvert.SerializeObject(order);
                var conten   = new StringContent(userJson, Encoding.UTF8, "application/json");
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));
                var response = await httpClient.PostAsync($"{AppSettings.APIURL}api/Orders", conten);

                var JsonResult = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <OrderResponce>(JsonResult));
            }
        }
Example #5
0
        public static async Task <bool> ClearShoppingCart(int userID)
        {
            await TokenValidator.CheckToken();

            using (HttpClient httpClient = new HttpClient()) {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));
                var response = await httpClient.DeleteAsync($"{AppSettings.APIURL}api/ShoppingCartItems/{userID}");

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }
                return(false);
            }
        }
Example #6
0
        public static async Task <bool> AddItemsToCart(AddToCart addToCart)
        {
            await TokenValidator.CheckToken();

            using (HttpClient httpClient = new HttpClient()) {
                var userJson = JsonConvert.SerializeObject(addToCart);
                var conten   = new StringContent(userJson, Encoding.UTF8, "application/json");
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("token", string.Empty));
                var response = await httpClient.PostAsync($"{AppSettings.APIURL}api/ShoppingCartItems", conten);

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