public static async Task <List <ProductByCategory> > 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 <ProductByCategory> >(response)); }
public static async Task <TotalCartItem> 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 <TotalCartItem>(response)); }
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)); }
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); }
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); }