Beispiel #1
0
        public async Task <Eleve> AddEleveByIdClassroom(int idClassroom, EleveAdded eleve)
        {
            try
            {
                if (DataManager.Instance.CurrentUser == null || !IsConnected)
                {
                    throw new Exception();
                }

                var serializedItem           = JsonConvert.SerializeObject(eleve);
                HttpResponseMessage response = await _client.PostAsync(
                    string.Format(ApiConstantes.Eleves, idClassroom),
                    new StringContent(serializedItem, Encoding.UTF8, "application/json")
                    );

                if (response.IsSuccessStatusCode)
                {
                    //Set the current User for the application
                    string content = await response.Content.ReadAsStringAsync();

                    return(JsonConvert.DeserializeObject <Eleve>(content));
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erreur lors de la création d'un nouvel élève");
            }
        }
        // =============================================================================

        private async void BtnValider_Clicked(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(EntryName.Text) && !string.IsNullOrEmpty(EntryPrenom.Text))
                {
                    ShowLoader();

                    EleveAdded part = new EleveAdded();
                    part.Nom    = EntryName.Text;
                    part.Prenom = EntryPrenom.Text;

                    await DataManager.Instance.AddEleve(_currentClasse.Id, part);

                    UpdateUI();

                    EntryName.Text   = "";
                    EntryPrenom.Text = "";

                    EntryName.Focus();
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Oups", "Un problème à eu lieu lors de l'ajout d'un élève", "Ok");
            }
            finally
            {
                HideLoader();
            }
        }
Beispiel #3
0
        public async Task AddEleve(int idClassroom, EleveAdded e)
        {
            try
            {
                Eleve eleve = await ApiManager.Instance.AddEleveByIdClassroom(idClassroom, e);

                ListEleves.Add(eleve);
            }
            catch (Exception ex)
            {
                AlertError.ShowErrorAlert(ex.Message);
            }
        }