示例#1
0
        // ----------- Fonction de connexion de l'utilisateur --> retourne un JSON qui contient le token de session ----------
        public async void conUser(User user)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://demo.comte.re");
                var json     = JsonConvert.SerializeObject(user);
                var itemJson = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage responseAPI = await client.PostAsync("/api/auth/login", itemJson);

                if (responseAPI.IsSuccessStatusCode)
                {
                    String _response = responseAPI.Content.ReadAsStringAsync().Result;
                    this.Api = new APIculteur();
                    this.Api = JsonConvert.DeserializeObject <APIculteur>(_response);

                    currentFrame.Navigate(typeof(Salon), this.Api);
                    var dialog = new MessageDialog("Vous êtes connecté");

                    await dialog.ShowAsync();
                }
                else
                {
                    var res = await responseAPI.Content.ReadAsStringAsync();

                    var dialog = new MessageDialog("Connexion refuse", res);
                    await dialog.ShowAsync();
                }
            }
        }
 public TableViewModel(APIculteur Api)
 {
     this._api = Api;
     getTables();
 }