// Check infos and try sign in
        private async Task SignInButton_ClickedAsync(object sender, EventArgs e)
        {
            Animations.ButtonFadeAnimation(sender as Button);

            var Content = new StringContent(JsonConvert.SerializeObject(new Data.Model.User()
            {
                Name     = NameEntry.Text,
                Surname  = SurnameEntry.Text,
                Mail     = MailEntry.Text,
                Password = PasswordEntry.Text,
                Gender   = GenderPicker.SelectedItem.ToString(),
                Birthday = BirthdayPicker.Date,
                Height   = Convert.ToInt32(HeightPicker.SelectedItem),
                Weight   = Convert.ToInt32(WeightPicker.SelectedItem)
            }), Encoding.UTF8, "application/json");

            try
            {
                HttpResponseMessage Response = await App.Client.PostAsync($"http://{App.ServerAddress}/PLSport/WebService/SignIn.php", Content);

                if (Response.IsSuccessStatusCode)
                {
                    await DisplayAlert("Bienvenue", "Votre compte a bien été créé, vous pouvez désormais vous connecter.", "OK");

                    await Navigation.PopModalAsync(true);
                }
                else
                {
                    DisplayAlert("Erreur", "Mail déjà utilisé par un autre utilisateur.", "OK");
                }
            }
            catch { DisplayAlert("Erreur", "Aucune réponse du serveur. Veuillez réessayer ultérieurement.", "OK"); }
        }
        // Add new weight to database and refresh chart
        private async void AddWeightButton_ClickedAsync(object sender, EventArgs e)
        {
            Animations.ButtonFadeAnimation(sender as Button);

            var Content = new StringContent(JsonConvert.SerializeObject(new Data.Model.Weight()
            {
                Value   = Convert.ToInt32(WeightEntry.Text),
                User_ID = ConnectedUser.ID
            }), Encoding.UTF8, "application/json");

            try
            {
                HttpResponseMessage Response = await App.Client.PostAsync($"http://{App.ServerAddress}/PLSport/WebService/PostWeight.php", Content);

                if (Response.IsSuccessStatusCode)
                {
                    WeightEntry.Text = "";
                    GetWeights();
                }
                else
                {
                    DisplayAlert("Erreur", "Impossible d'ajouté un nouveau poids, veuillez réessayer ultérieurement.", "OK");
                }
            }
            catch { DisplayAlert("Erreur", "Aucune réponse du serveur. Veuillez réessayer ultérieurement.", "OK"); }
        }
Exemple #3
0
        // Add new event, and subscribe the coach to the event
        private async void AddButton_ClickedAsync(object sender, EventArgs e)
        {
            Animations.ButtonFadeAnimation(sender as Button);
            if (String.IsNullOrWhiteSpace(NameEntry.Text))
            {
                DisplayAlert("Attention", "Vous n'avez pas donnez de nom a l'événement.", "OK");
            }
            else
            {
                var Content = new StringContent(JsonConvert.SerializeObject(new Event()
                {
                    Name        = NameEntry.Text,
                    Description = DescriptionEntry.Text,
                    Date        = DatePicker.Date.Add(TimePicker.Time),
                    Place       = Convert.ToInt32(PlaceEntry.Text) + 1, // + 1 for the coach
                    Type_ID     = TypePicker.SelectedIndex + 1,
                    Owner_ID    = ConnectedUser.ID
                }), Encoding.UTF8, "application/json");

                try
                {
                    HttpResponseMessage Response = await App.Client.PostAsync($"http://{App.ServerAddress}/PLSport/WebService/PostEvent.php", Content);

                    if (Response.IsSuccessStatusCode)
                    {
                        var Content2 = new StringContent(JsonConvert.SerializeObject(new UserHasEvent()
                        {
                            User_ID  = ConnectedUser.ID,
                            Event_ID = Convert.ToInt32((await Response.Content.ReadAsStringAsync()).Split('|')[1]),
                            Type     = "Insert"
                        }), Encoding.UTF8, "application/json");

                        try
                        {
                            HttpResponseMessage Response2 = await App.Client.PostAsync($"http://{App.ServerAddress}/PLSport/WebService/PostUserHasEvent.php", Content2);

                            if (Response2.IsSuccessStatusCode)
                            {
                                await DisplayAlert("Succès", "Ajout de l'événement effectué.", "OK");

                                await Navigation.PopAsync(true);
                            }
                            else
                            {
                                DisplayAlert("Erreur", "Impossible d'ajouter un événement. [UHE]", "OK");
                            }
                        }
                        catch { DisplayAlert("Erreur", "Aucune réponse du serveur. [UHE]", "OK"); }
                    }
                    else
                    {
                        DisplayAlert("Erreur", "Impossible d'ajouter un événement. [PE]", "OK");
                    }
                }
                catch { DisplayAlert("Erreur", "Aucune réponse du serveur. [PE]", "OK"); }
            }
        }
 // Log in button click event
 private async void LogInButton_Clicked(object sender, EventArgs e)
 {
     if (!IsAlreadyClicked)
     {
         IsAlreadyClicked = true;
         Animations.ButtonFadeAnimation(sender as Button);
         await LogIn(MailEntry.Text, PasswordEntry.Text);
     }
     IsAlreadyClicked = false;
 }
 // Go to sign in page
 private async void OpenSignInButton_Clicked(object sender, EventArgs e)
 {
     Animations.ButtonFadeAnimation(sender as Button);
     await Navigation.PushModalAsync(new SignInPage(), true);
 }