protected void Carregar()
        {
            if (uplImagemCarregada.PostedFile != null && uplImagemCarregada.PostedFile.FileName != "")
            {
                Configuracao_Model model = new Configuracao_Model();

                // cria as variáveis que serão passadas por referência
                String fileName = Path.GetFileName(uplImagemCarregada.FileName);
                bool   enviado  = false;

                // chama a função passando as variáveis de referência. O retorno é a mensagem de sucesso ou erro
                String msg = model.EnviarArquivoServidor(ref fileName, uplImagemCarregada.FileBytes, ref enviado);

                // verifica se foi enviado e exibe a mensagem e a imagem na tela
                if (enviado)
                {
                    Master.Sucesso(msg);
                    imgImagemCarregada.ImageUrl = fileName;
                }
                else
                {
                    Master.Alerta(msg);
                }
            }
        }
        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            CasosMediacao_Model model = new CasosMediacao_Model();
            casos_mediacao      cm    = new casos_mediacao();

            if (Validar())
            {
                // pega nome da imagem e caminho
                configuracao       c  = new configuracao();
                Configuracao_Model mc = new Configuracao_Model();

                c = mc.Obter("medPortal");

                String caminho = c.caminho_images;
                String nome    = Path.GetFileName(imgImagemCarregada.ImageUrl);
                // pega mediador logado
                mediador med = Master.GetLogado();

                cm.id_tipo_registro = int.Parse(ddTipoRegistro.SelectedValue);
                cm.titulo           = txtTitulo.Text;
                cm.descricao        = txtDescricao.Value;
                cm.prioridade       = int.Parse(ddPrioridade.SelectedValue);
                cm.imagem_caminho   = caminho;
                cm.imagem_nome      = nome;
                cm.id_mediador      = med.id;
                cm.data             = DateTime.Now;

                if (model.Inserir(cm))
                {
                    Master.Sucesso("Caso registrado com sucesso.");
                }
                else
                {
                    if (model.Alterar(cm))
                    {
                        Master.Sucesso("Caso atualizado com sucesso.");
                    }
                    else
                    {
                        Master.Alerta("Erro ao registrar: " + model.message);
                    }
                }
            }
        }
Beispiel #3
0
        protected void SalvarNoticia()
        {
            // Validar se esta editando ou postando nova
            // se estiver editando, alterar somente titulo, texto e imagem, mantendo a data
            try
            {
                if (Validar())
                {
                    configuracao       c  = new configuracao();
                    Configuracao_Model mc = new Configuracao_Model();

                    c = mc.Obter("medPortal");

                    // salva o caminho das imagens no servidor ftp
                    String caminho = c.caminho_images;
                    // pega o nome da imagem carregada na tela
                    String nome = Path.GetFileName(imgImagemCarregada.ImageUrl);

                    // declara objeto noticia
                    noticia n = new noticia();
                    // declara objeto noticia_model
                    Noticia_Model model = new Noticia_Model();
                    // pega o mediador logado
                    mediador med = Session["med"] as mediador;

                    n.titulo_postagem = txtTituloNoticia.Text;
                    n.corpo_noticia   = edtNoticia.Value;
                    n.imagem_caminho  = caminho;
                    n.imagem_nome     = nome;
                    n.prioridade      = int.Parse(ddPrioridade.SelectedValue);

                    if (Request.QueryString["ID"] != null)
                    {
                        // se tem ID, altera
                        int id = int.Parse(Request.QueryString["ID"]);

                        n.id                 = id;
                        n.data_edicao        = DateTime.Now;
                        n.id_local_edicao    = med.id_local;
                        n.id_mediador_edicao = med.id;

                        if (model.Alterar(n))
                        {
                            Master.Sucesso("Notícia alterada!");
                            Response.Redirect("noticias.aspx");
                        }
                        else
                        {
                            Master.Alerta("Erro: " + model.message);
                        }
                    }
                    else
                    {
                        // se não tem ID, insere
                        n.data_postagem = DateTime.Now;
                        n.id_local      = med.id_local;
                        n.id_mediador   = med.id;

                        if (model.Inserir(n))
                        {
                            Master.Sucesso("Notícia postada!");
                            Response.Redirect("noticias.aspx");
                        }
                        else
                        {
                            Master.Alerta("Erro: " + model.message);
                        }
                    }
                }
            }
            catch (Exception Exc)
            {
                Master.Alerta("Erro: " + Exc.Message);
            }
        }