Exemplo n.º 1
0
 private async void signup()
 {
     loading_animation.Begin();
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri(@"http://pubbus-coeus.azurewebsites.net/");
         client.DefaultRequestHeaders.Accept.Clear();
         client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
         Users user =new Users();
         //user.name = "admin";
         user.email = user_name.Text;
         user.password = password.Password;
         HttpResponseMessage response = await client.PostAsJsonAsync("api/users/",user);
         if (response.StatusCode == HttpStatusCode.Created)
         {
             Printf("Thanh cong");
         }
         else if (response.StatusCode == HttpStatusCode.Conflict)
         {
             Printf("Trung");
         }
         else
         {
             Printf(response.StatusCode.ToString());
         }
         loading_animation.Stop();
     }
 }
Exemplo n.º 2
0
 private async void register_Btn_Click(object sender, RoutedEventArgs e)
 {
     Users user=new Users();
     user.email = user_name.Text;
     user.password = password.Password;
     using (var client = new HttpClient())
     {
         try
         {
             client.BaseAddress = new Uri(@"http://pubbus-coeus.azurewebsites.net/");
             client.DefaultRequestHeaders.Accept.Clear();
             client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
             HttpResponseMessage response = await client.PostAsJsonAsync("api/users/",user);
             MessageDialog dl = new MessageDialog(response.StatusCode.ToString());
             await dl.ShowAsync();
             if (response.StatusCode == HttpStatusCode.Created)
             {
                 dl = new MessageDialog("Thanh cong");
                 await dl.ShowAsync();
             }
             else if (response.StatusCode == HttpStatusCode.Conflict)
             {
                 dl = new MessageDialog("Tai khoan da ton tai");
                 await dl.ShowAsync();
             }
             else
             {
                 dl = new MessageDialog(response.StatusCode+"\n"+response.ReasonPhrase);
                 await dl.ShowAsync();
             }
         }
         catch (Exception ex)
         {
             Printf(ex.Message);
         }
     }
 }