예제 #1
0
        protected async void enviarButton_Click(object sender, EventArgs e)
        {
            try
            {
                var cliente = ClientesDao.BuscarCliente(documentoTextBox.Text);
                if (cliente == null)
                {
                    throw new Exception("Não existe nenhum cliente com documento informado");
                }
                Chamado chamado = new Chamado();
                chamado.Assunto   = assuntoDropDownList.SelectedValue;
                chamado.Documento = documentoTextBox.Text;
                chamado.Descricao = descricaoTextBox.Text;

                // criando o objeto no formato JSON

                string json = JsonConvert.SerializeObject(chamado);

                //definindo o json para um fluxo de bytes
                HttpContent content = new StringContent(json, Encoding.Unicode, "application/json");

                //enviando o objeto serializado para o webservice

                var response = await client.PostAsync("api/chamados", content);


                // verifficando se ocorreu a incluão corretamente

                if (response.IsSuccessStatusCode)
                {
                    mensagemLabel.CssClass = "alert alert-sucess";
                    mensagemLabel.Text     = "Chamado aberto com sucesso";
                }
                else
                {
                    string erro = response.StatusCode + "-" + response.ReasonPhrase;
                    throw new Exception(erro);
                }
            }
            catch (Exception ex)
            {
                mensagemLabel.CssClass = "alert alert-danger";
                mensagemLabel.Text     = ex.Message;
            }
        }
        private ActionResult VerificarCliente(int id, string view)
        {
            try
            {
                var cliente = ClientesDao.BuscarCliente(id);

                if (cliente == null)
                {
                    throw new Exception("Cliente não existe, ou CPF não informado");
                }

                return(View(view, cliente));
            }
            catch (Exception ex)
            {
                ViewBag.MensagemErro = ex.Message;
                return(View("_Erro"));
            }
        }
예제 #3
0
        protected async void enviarButton_Click(object sender, EventArgs e)
        {
            try
            {
                var cliente = ClientesDao.BuscarCliente(documentoTextBox.Text);
                if (cliente == null)
                {
                    throw new Exception("Não existe nenhum cliente com o ducumento informado");
                }
                Chamado chamado = new Chamado();
                chamado.Assunto   = assuntoDropDownList.Text;
                chamado.Descricao = descricaoTextBox.Text;
                chamado.Documento = documentoTextBox.Text;

                string json = JsonConvert.SerializeObject(chamado);

                HttpContent content = new StringContent(json, Encoding.Unicode, "application/json");

                var response = await client.PostAsync("api/chamados", content);

                if (response.IsSuccessStatusCode)
                {
                    mensagemLabel.CssClass = "alert alert-success";
                    mensagemLabel.Text     = "Chamado aberto com sucesso";
                }
                else
                {
                    string erro = response.StatusCode + " - " + response.ReasonPhrase;
                    throw new Exception(erro);
                }
            }
            catch (Exception ex)
            {
                mensagemLabel.CssClass = "alert alert-danger";
                mensagemLabel.Text     = ex.Message;
            }
        }