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)); }
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)); }
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)); }
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)); }
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); }
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); }
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; } }
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)); }