private void VerificarErro(string resposta)
 {
     if (resposta.ToLower().Contains("codigoerro"))
     {
         Model.ErroModel erro = JsonConvert.DeserializeObject <Model.ErroModel>(resposta);
         throw new ArgumentException(erro.Mensagem);
     }
 }
예제 #2
0
        private string VerificarErroCorreto(HttpResponseMessage respostaAPI)
        {
            string jsonResposta = respostaAPI.Content.ReadAsStringAsync().Result;

            if (respostaAPI.IsSuccessStatusCode == false)
            {
                Model.ErroModel erro = JsonConvert.DeserializeObject <Model.ErroModel>(jsonResposta);
                throw new ArgumentException(erro.Mensagem);
            }
            return(jsonResposta);
        }
        public string LerJson(HttpResponseMessage RespostaAPI)
        {
            string Json = RespostaAPI.Content.ReadAsStringAsync().Result;

            if (RespostaAPI.IsSuccessStatusCode == false)
            {
                Model.ErroModel erro = JsonConvert.DeserializeObject <Model.ErroModel>(Json);
                throw new ArgumentException(erro.Mensagem);
            }

            return(Json);
        }
        public void Remover(int id)
        {
            HttpClient client = new HttpClient();
            var        resp   = client.DeleteAsync("http://localhost:5000/Turma/" + id).Result;

            string jsonResposta = resp.Content.ReadAsStringAsync().Result;

            if (resp.IsSuccessStatusCode == false)
            {
                Model.ErroModel erro = JsonConvert.DeserializeObject <Model.ErroModel>(jsonResposta);
                throw new ArgumentException(erro.Mensagem);
            }
        }
예제 #5
0
        public void Remover(int id)
        {
            var json = client.DeleteAsync("http://localhost:5000/Curso/" + id).Result;

            if (json.IsSuccessStatusCode == false)
            {
                string jsonResposta = json.Content
                                      .ReadAsStringAsync()
                                      .Result;

                Model.ErroModel erro = JsonConvert.DeserializeObject <Model.ErroModel>(jsonResposta);
            }
        }
        public void Deletar(int id)
        {
            var resp = client.DeleteAsync("http://localhost:5000/ProfessorDisciplina/" + id).Result;

            if (resp.IsSuccessStatusCode == false)
            {
                string jsonResposta = resp.Content
                                      .ReadAsStringAsync()
                                      .Result;

                Model.ErroModel erro = JsonConvert.DeserializeObject <Model.ErroModel>(jsonResposta);
                throw new ArgumentException(erro.Mensagem);
            }
        }
예제 #7
0
        public void AlterarCurso(Model.CursoModel curso)
        {
            string        json     = JsonConvert.SerializeObject(curso);
            StringContent body     = new StringContent(json, Encoding.UTF8, "application/json");
            var           resposta = client.PutAsync("http://localhost:5000/Curso/", body).Result;

            if (resposta.IsSuccessStatusCode == false)
            {
                string jsonResposta = resposta.Content
                                      .ReadAsStringAsync()
                                      .Result;

                Model.ErroModel erro = JsonConvert.DeserializeObject <Model.ErroModel>(jsonResposta);
                throw new Exception(erro.Mensagem);
            }
        }
        public void Remover(int id)
        {
            string json = JsonConvert.SerializeObject(id);

            HttpResponseMessage respota = client.DeleteAsync($"http://localhost:5000/Diciplina/Remover/{id}").Result;

            if (respota.IsSuccessStatusCode == false)
            {
                string jsonResposta = respota.Content
                                      .ReadAsStringAsync()
                                      .Result;

                Model.ErroModel erro = JsonConvert.DeserializeObject <Model.ErroModel>(jsonResposta);
                throw new ArgumentException(erro.Mensagem);
            }
        }
        public void InserirTurma(Nsf.App.Model.TurmaModel turma)
        {
            HttpClient client = new HttpClient();

            string        json = JsonConvert.SerializeObject(turma);
            StringContent body = new StringContent(json, Encoding.UTF8, "application/json");

            var resp = client.PostAsync("http://localhost:5000/Turma/", body).Result;

            string jsonResposta = resp.Content.ReadAsStringAsync().Result;

            if (resp.IsSuccessStatusCode == false)
            {
                Model.ErroModel erro = JsonConvert.DeserializeObject <Model.ErroModel>(jsonResposta);
                throw new ArgumentException(erro.Mensagem);
            }
        }
        public void Alterar(Model.ProfessorDisciplinaModel professordisciplna)
        {
            string        json = JsonConvert.SerializeObject(professordisciplna);
            StringContent body = new StringContent(json, Encoding.UTF8, "application/json");

            var resp = client.PutAsync("http://localhost:5000/ProfessorDisciplina/", body).Result;

            if (resp.IsSuccessStatusCode == false)
            {
                string jsonResposta = resp.Content
                                      .ReadAsStringAsync()
                                      .Result;

                Model.ErroModel erro = JsonConvert.DeserializeObject <Model.ErroModel>(jsonResposta);
                throw new ArgumentException(erro.Mensagem);
            }
        }