Exemple #1
0
        public static async Task <List <ProductCategory> > GetProductByCategory(int categoryId)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + "api/Products/ProductsByCategory/" + categoryId);

            return(JsonConvert.DeserializeObject <List <ProductCategory> >(response));
        }
Exemple #2
0
        public static async Task <List <Order> > GetOrderDetails(int orderId)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + "api/Orders/OrderDetails/" + orderId);

            return(JsonConvert.DeserializeObject <List <Order> >(response));
        }
Exemple #3
0
        public static async Task <ItemInCart> GetTotalCartItems(int userId)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + "api/ShoppingCartItems/TotalItems/" + userId);

            return(JsonConvert.DeserializeObject <ItemInCart>(response));
        }
Exemple #4
0
        public static async Task <OrderResponse> PlaceOrder(Order order)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(order);
            var content    = new StringContent(json, Encoding.UTF8, "application/json");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = await httpClient.PostAsync(AppSettings.ApiUrl + "api/Orders", content);

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

            return(JsonConvert.DeserializeObject <OrderResponse>(jsonResult));
        }
Exemple #5
0
        public static async Task <bool> ClearShoppingCart(int userId)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = await httpClient.DeleteAsync(AppSettings.ApiUrl + "api/ShoppingCartItems/" + userId);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
Exemple #6
0
        public static async Task <bool> AddItemsInCart(AddToCart addToCart)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();
            var json       = JsonConvert.SerializeObject(addToCart);
            var content    = new StringContent(json, Encoding.UTF8, "application/json");

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", string.Empty));
            var response = await httpClient.PostAsync(AppSettings.ApiUrl + "api/ShoppingCartItems", content);

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