public async void logIn(string username, string password){ Dictionary<string, string> body = new Dictionary<string, string> (); body.Add ("grant_type", "password"); body.Add ("client_id", "e99d11d1-6504-4abf-8aa0-886e4affe6a0"); body.Add ("client_secret", "d650639e9fe3110f4024149f0d98e04cbde0305d"); body.Add ("username", username); body.Add ("password", password); WebService webservice = new WebService(); JsonValue json = await webservice.Call (WebService.OAUTH_TOKEN, WebService.Method.POST, null, body, null); if (json != null) { var result = JsonValue.Parse (json.ToString ()); Console.WriteLine ("\n \n \n \n========WEBSERVICE======= "); if (result.ContainsKey ("code") && result ["code"].Equals ("400")) { } else { if ((string)result ["access_token"] != null) { Console.WriteLine ("user is loged in: {0}", result ["access_token"]); App.token = result ["access_token"]; Console.WriteLine (App.token); await Navigation.PushAsync (new Products ()); } } } }
private async void getCategoryListFromWebService(){ Dictionary<string, string> headers = new Dictionary<string, string> (); headers.Add("Authorization", "Bearer " + App.token); Dictionary<string, string> parameter = new Dictionary<string, string> (); parameter.Add("store_uid", store.uid); WebService webService = new WebService(); JsonValue result = await webService.Call (WebService.CATEGORY_LIST_URL, WebService.Method.GET, parameter, null, headers); if (result.ContainsKey("result")) { JsonValue jsonCategoriesList = result["result"]; foreach (JsonValue category in jsonCategoriesList){categoriesList.Add(Category.Deserialize(category));} list.ItemsSource = categoriesList; list.ItemTemplate = new DataTemplate(typeof(TextCell)); list.ItemTemplate.SetBinding(TextCell.TextProperty, "name"); list.ItemSelected += async (sender, e) => { Category selectedCategory = (Category)e.SelectedItem; Navigation.InsertPageBefore (new ProductList(selectedCategory), this); await Navigation.PopAsync (); }; } }
public async void getToken(){ Dictionary<string, string> body = new Dictionary<string, string> (); body.Add ("grant_type", "client_credentials"); body.Add ("client_id", "e99d11d1-6504-4abf-8aa0-886e4affe6a0"); body.Add ("client_secret", "d650639e9fe3110f4024149f0d98e04cbde0305d"); WebService webservice = new WebService(); JsonValue json = await webservice.Call (WebService.OAUTH_TOKEN, WebService.Method.POST, null, body, null); var result = JsonValue.Parse (json.ToString ()); Console.WriteLine ("\n \n \n \n WEBSERVICE "); Console.WriteLine ("token is : {0}",result["access_token"]); App.token = result ["access_token"]; }
private async void getProductList(){ Dictionary<string, string> headers = new Dictionary<string, string> (); headers.Add ("Authorization", "Bearer " + App.token); Dictionary<string, string> parameter = new Dictionary<string, string> (); parameter.Add ("category_uid", category.uid); WebService webservice = new WebService (); JsonValue result = await webservice.Call(WebService.PRODUCT_LIST_URL, WebService.Method.GET, parameter, null, headers); if (result.ContainsKey("result")) { JsonValue productListJson = result["result"]; foreach (JsonValue product in productListJson){productsList.Add(Product.Deserialize(product));} list.ItemsSource = productListJson; list.ItemTemplate = new DataTemplate(typeof(TextCell)); } }
public async void Rigister(){ Dictionary<string, string> body = new Dictionary<string, string> (); body.Add ("email", this.email); body.Add ("password", this.password); body.Add ("firstname", this.firstname); body.Add ("lastname", this.lastname); Dictionary<string, string> headers = new Dictionary<string, string> (); body.Add ("Authorization", "Bearer "+App.token); WebService webservice = new WebService(); JsonValue json = await webservice.Call (WebService.OAUTH_TOKEN, WebService.Method.POST, null, body, headers); var result = JsonValue.Parse (json.ToString ()); Console.WriteLine ("\n \n \n \n========WEBSERVICE======= "); Console.WriteLine ("user is created : {0}",result["uid"]); }