示例#1
0
        public async Task <Matiere> AddMatiereByIdClassroom(int idClassroom, MatiereAdded mat)
        {
            try
            {
                if (DataManager.Instance.CurrentUser == null || !IsConnected)
                {
                    throw new Exception();
                }

                var serializedItem           = JsonConvert.SerializeObject(mat);
                HttpResponseMessage response = await _client.PostAsync(
                    string.Format(ApiConstantes.Matieres, 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 <Matiere>(content));
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erreur lors de la création d'une nouvelle matière");
            }
        }
示例#2
0
 public async Task <Matiere> AddMatiere(int idClassroom, MatiereAdded e)
 {
     try
     {
         return(await ApiManager.Instance.AddMatiereByIdClassroom(idClassroom, e));
     }
     catch (Exception ex)
     {
         AlertError.ShowErrorAlert(ex.Message);
         return(null);
     }
 }