Esempio n. 1
0
        public async Task <Classe> AddClassroom(ClasseAdded classe)
        {
            try
            {
                if (DataManager.Instance.CurrentUser == null || !IsConnected)
                {
                    throw new Exception();
                }

                var serializedItem           = JsonConvert.SerializeObject(classe);
                HttpResponseMessage response = await _client.PostAsync(
                    ApiConstantes.Classrooms,
                    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 <Classe>(content));
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erreur lors de la création d'une nouvelle classe");
            }
        }
        private async void ClasseEntry_Completed(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(ClasseEntry.Text))
                {
                    ShowLoader();

                    ClasseAdded c = new ClasseAdded();
                    c.Nom = ClasseEntry.Text;

                    await DataManager.Instance.AddClasse(c);

                    ClasseEntry.Text = "";

                    List <Classe> list      = DataManager.Instance.ListClasses.OrderBy(x => x.Nom).ToList();
                    Classe        newClasse = list.Find(x => x.Nom == c.Nom);
                    int           index     = list.IndexOf(newClasse);

                    ClassesPicker.SelectedIndex = index;
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                HideLoader();
            }
        }
Esempio n. 3
0
        // =============================================================================
        #region Classes
        public async Task AddClasse(ClasseAdded c)
        {
            try
            {
                if (ListClasses.FirstOrDefault(x => x.Nom == c.Nom) != null)
                {
                    throw new Exception("Une classe avec ce nom existe déjà !");
                }

                Classe classroom = await ApiManager.Instance.AddClassroom(c);

                ListClasses.Add(classroom);
            }
            catch (Exception ex)
            {
                AlertError.ShowErrorAlert(ex.Message);
            }
        }