コード例 #1
0
        public static async Task <Product> GetProductById(int productId)
        {
            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/" + productId);

            return(JsonConvert.DeserializeObject <Product>(response));
        }
コード例 #2
0
        public static async Task <List <OrderByUser> > GetOrdersByUser(Guid 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/Orders/OrdersByUser/" + userId);

            return(JsonConvert.DeserializeObject <List <OrderByUser> >(response));
        }
コード例 #3
0
        public static async Task <CartSubTotal> GetCartSubTotal(Guid 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/SubTotal/" + userId);

            return(JsonConvert.DeserializeObject <CartSubTotal>(response));
        }
コード例 #4
0
        public async Task <OrderResponse> PlaceOrder(Order entity)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", String.Empty));
            var json     = JsonConvert.SerializeObject(entity);
            var contant  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await httpClient.PostAsync(baseUrl + "Orders", contant);

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

            return(JsonConvert.DeserializeObject <OrderResponse>(jsonResult));
        }
コード例 #5
0
        public static async Task <bool> ClearShoppingCart(Guid 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);
        }
コード例 #6
0
        public async Task <bool> AddItemInCart(AddToCart entity)
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", String.Empty));
            var json     = JsonConvert.SerializeObject(entity);
            var contant  = new StringContent(json, Encoding.UTF8, "application/json");
            var response = await httpClient.PostAsync(baseUrl + "ShoppingCartItems", contant);

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }
            return(true);
        }
コード例 #7
0
        public static async Task <List <Category> > GetCategories()
        {
            try
            {
                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/Categories");

                return(JsonConvert.DeserializeObject <List <Category> >(response));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
        public async Task <List <Category> > GetCategories()
        {
            await TokenValidator.CheckTokenValidity();

            var httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", Preferences.Get("accessToken", String.Empty));
            var response = await httpClient.GetAsync(baseUrl + "Categories");

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


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

            return(JsonConvert.DeserializeObject <List <Category> >(jsonResult));
        }