Esempio n. 1
0
    public ActionResult CreateAluno(AlunoViewModel alunoViewModel)
    {
        if (ModelState.IsValid)
        {
            var Usuario = db.Usuario.Where(u => u.Email.ToUpper() == alunoViewModel.Email.ToUpper()).FirstOrDefault();
            if (Usuario != null)
            {
                ModelState.AddModelError("email", "E-mail já cadastrado na base");
            }
            else
            {
                ALUNO aluno = new ALUNO()
                {
                    NOME    = alunoViewModel.Nome,
                    Usuario = new Usuario()
                    {
                        Email         = alunoViewModel.Email,
                        HashSenha     = GerarHash(alunoViewModel.Senha),
                        FlagSenhaTemp = alunoViewModel.SenhaTemporaria ? "S" : "N"
                    }
                };
                db.ALUNO.Add(aluno);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }

        return(View(alunoViewModel));
    }
Esempio n. 2
0
    public ActionResult EditAluno(AlunoViewModel AlunoViewModel)
    {
        if (ModelState.IsValid)
        {
            ALUNO Aluno = db.ALUNO.Find(AlunoViewModel.Alunoid);

            var Usuario = db.Usuario.Where(u => u.Email.ToUpper() == AlunoViewModel.Email.ToUpper()).FirstOrDefault();
            if (Usuario != null && Aluno.Usuario.UsuarioId != Usuario.UsuarioId)
            {
                ModelState.AddModelError("email", "E-mail já cadastrado na base");
            }
            else
            {
                Aluno.NOME                  = AlunoViewModel.Nome;
                Aluno.Usuario.Email         = AlunoViewModel.Email;
                Aluno.Usuario.HashSenha     = GerarHash(AlunoViewModel.Senha);
                Aluno.Usuario.FlagSenhaTemp = AlunoViewModel.SenhaTemporaria ? "S" : "N";

                db.Entry(Aluno).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }

        return(View(AlunoViewModel));
    }
Esempio n. 3
0
        public JsonResult Cadastrar(ALUNO aluno)
        {
            try
            {
                if (aluno is ALUNO)
                {
                    eSecretariaEntities context = new eSecretariaEntities();
                    context.ALUNO.Add(aluno);
                    context.SaveChanges();
                }
                else
                {
                    return(Json(new ClasseRespostaCreate()
                    {
                        success = false,
                        message = "Erro ao criar aluno - cod 1"
                    }));
                }

                return(Json(new ClasseRespostaCreate()
                {
                    success = true,
                    message = "Aluno criado com sucesso"
                }));
            }catch (Exception ex)
            {
                return(Json(new ClasseRespostaCreate()
                {
                    success = false,
                    message = "Erro ao criar aluno - cod 2"
                }));
            }
        }
Esempio n. 4
0
    public ActionResult DeleteConfirmed(int id)
    {
        ALUNO aluno = db.ALUNO.Find(id);

        db.ALUNO.Remove(aluno);
        db.SaveChanges();
        return(RedirectToAction("Index"));
    }
Esempio n. 5
0
 public bool Cadastrar(ALUNO oAluno)
 {
     if (AlunoMetod.Cadastrar(oAluno))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 6
0
 public bool Alterar(ALUNO oAluno)
 {
     if (AlunoMetod.Alterar(oAluno))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 7
0
 public ActionResult Edit([Bind(Include = "Cod_Aluno,Nome_Aluno,UsuarioId")] ALUNO aluno)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aluno).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UsuarioId = new SelectList(db.Usuario, "UsuarioId", "Email", aluno.UsuarioId);
     return(View(aluno));
 }
Esempio n. 8
0
    public ActionResult Create([Bind(Include = "COD_ALUNO,Nome,UsuarioId")] ALUNO aluno)
    {
        if (ModelState.IsValid)
        {
            db.ALUNO.Add(aluno);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }

        ViewBag.UsuarioId = new SelectList(db.Usuario, "UsuarioId", "Email", aluno.UsuarioId);
        return(View(aluno));
    }
Esempio n. 9
0
 public ActionResult Edit([Bind(Include = "ID_ALUNO,NOME_ALUNO,CPF_ALUNO,TITULO_ELEITOR,ENDERECO_ALUNO,TELEFONE_ALUNO,RUA,NUMERO,COMPLEMENTO,BAIRRO,CEP,ID_FACULDADE,ID_ROTA,ID_TURNO_FACULDADE")] ALUNO aLUNO)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aLUNO).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ID_FACULDADE       = new SelectList(db.FACULDADE, "ID_FACULDADE", "NOME_FACULDADE", aLUNO.ID_FACULDADE);
     ViewBag.ID_ROTA            = new SelectList(db.ROTA, "ID_ROTA", "NOME_ROTA", aLUNO.ID_ROTA);
     ViewBag.ID_TURNO_FACULDADE = new SelectList(db.TURNO, "ID_TURNO", "DESCRICAO", aLUNO.ID_TURNO_FACULDADE);
     return(View(aLUNO));
 }
Esempio n. 10
0
        // GET: ALUNO/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ALUNO aLUNO = db.ALUNO.Find(id);

            if (aLUNO == null)
            {
                return(HttpNotFound());
            }
            return(View(aLUNO));
        }
Esempio n. 11
0
    // GET: Administrador/Details/5
    public ActionResult Details(int?id)
    {
        if (id == null)
        {
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
        ALUNO aluno = db.ALUNO.Find(id);

        if (aluno == null)
        {
            return(HttpNotFound());
        }
        return(View(aluno));
    }
Esempio n. 12
0
    // GET: Administrador/Edit/5
    public ActionResult Edit(int?id)
    {
        if (id == null)
        {
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
        ALUNO aluno = db.ALUNO.Find(id);

        if (aluno == null)
        {
            return(HttpNotFound());
        }
        ViewBag.UsuarioId = new SelectList(db.Usuario, "UsuarioId", "Email", aluno.UsuarioId);
        return(View(aluno));
    }
Esempio n. 13
0
        // GET: ALUNO/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ALUNO aLUNO = db.ALUNO.Find(id);

            if (aLUNO == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ID_FACULDADE       = new SelectList(db.FACULDADE, "ID_FACULDADE", "NOME_FACULDADE", aLUNO.ID_FACULDADE);
            ViewBag.ID_ROTA            = new SelectList(db.ROTA, "ID_ROTA", "NOME_ROTA", aLUNO.ID_ROTA);
            ViewBag.ID_TURNO_FACULDADE = new SelectList(db.TURNO, "ID_TURNO", "DESCRICAO", aLUNO.ID_TURNO_FACULDADE);
            return(View(aLUNO));
        }
Esempio n. 14
0
    public ActionResult EditAluno(int?id)
    {
        if (id == null)
        {
            return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
        }
        ALUNO Aluno = db.ALUNO.Find(id);

        if (Aluno == null)
        {
            return(HttpNotFound());
        }
        AlunoViewModel alunoViewModel = new AlunoViewModel()
        {
            Alunoid = Aluno.COD_ALUNO,
            Email   = Aluno.Usuario.Email,
            Nome    = Aluno.NOME
        };

        return(View(alunoViewModel));
    }
Esempio n. 15
0
        private void btnProcurar_Click(object sender, EventArgs e)
        {
            if (cmbPesquisa.SelectedIndex == 0)
            {
                int var = Convert.ToInt32(txtPesquisa.Text);
                CAluno.CAlunoClient oProxy = new CAluno.CAlunoClient();
                oProxy.Open();

                if (oProxy.Selecionar(var) != null)
                {
                    ALUNO oAluno = oProxy.Selecionar(var);

                    txtNome.Text      = oAluno.NOME;
                    txtSobreNome.Text = oAluno.SOBRENOME;
                    txtID.Text        = oAluno.ID_ALUNO.ToString();
                }
                else
                {
                    MessageBox.Show("Aluno não encontrado!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                CAluno.CAlunoClient oProxy = new CAluno.CAlunoClient();
                oProxy.Open();

                if (oProxy.SelecionarNome(txtPesquisa.Text) != null)
                {
                    ALUNO oAluno = oProxy.SelecionarNome(txtPesquisa.Text);

                    txtNome.Text      = oAluno.NOME;
                    txtSobreNome.Text = oAluno.SOBRENOME;
                    txtID.Text        = oAluno.ID_ALUNO.ToString();
                }
                else
                {
                    MessageBox.Show("Aluno não encontrado!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void btnAlterar_Click(object sender, EventArgs e)
        {
            ALUNO oAluno = new ALUNO();

            oAluno.NOME      = txtNome.Text;
            oAluno.SOBRENOME = txtSobreNome.Text;
            oAluno.NASC      = dtpNasc.Value;
            oAluno.CPF       = txtCPF.Text;
            oAluno.ENDERECO  = txtEnd.Text;
            oAluno.BAIRRO    = txtBairro.Text;
            oAluno.CIDADE    = txtCidade.Text;
            oAluno.UF        = cmbUF.SelectedItem.ToString();
            oAluno.PAIS      = cmbPais.SelectedItem.ToString();
            oAluno.CEP       = txtCEP.Text;
            oAluno.TEL_RES   = txtTelRes.Text;
            oAluno.TEL_CEL   = txtTelCel.Text;
            oAluno.EMAIL     = txtEmail.Text;

            CAluno.CAlunoClient oProxy = new CAluno.CAlunoClient();
            oProxy.Open();

            try
            {
                if (oProxy.Alterar(oAluno))
                {
                    MessageBox.Show("Alteração realizada com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LimpaCampos();

                    txtNome.Enabled      = true;
                    txtSobreNome.Enabled = true;
                    txtCPF.Enabled       = true;
                    dtpNasc.Enabled      = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnProcurar_Click(object sender, EventArgs e)
        {
            int var = Convert.ToInt32(txt_ID.Text);

            CAluno.CAlunoClient oProxy = new CAluno.CAlunoClient();
            oProxy.Open();

            if (oProxy.Selecionar(var) != null)
            {
                ALUNO oAluno = AlunoMetod.Selecionar(var);

                txtNome.Text         = oAluno.NOME;
                txtSobreNome.Text    = oAluno.SOBRENOME;
                dtpNasc.Value        = oAluno.NASC;
                txtCPF.Text          = oAluno.CPF;
                txtEnd.Text          = oAluno.ENDERECO;
                txtBairro.Text       = oAluno.BAIRRO;
                txtCidade.Text       = oAluno.CIDADE;
                cmbUF.SelectedItem   = oAluno.UF;
                cmbPais.SelectedItem = oAluno.PAIS;
                txtCEP.Text          = oAluno.CEP;
                txtTelRes.Text       = oAluno.TEL_RES;
                txtTelCel.Text       = oAluno.TEL_CEL;
                txtEmail.Text        = oAluno.EMAIL;
                txtID.Text           = oAluno.ID_ALUNO.ToString();

                txtNome.Enabled      = false;
                txtSobreNome.Enabled = false;
                txtCPF.Enabled       = false;
                dtpNasc.Enabled      = false;
            }
            else
            {
                MessageBox.Show("Aluno não encontrado!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 18
0
        ///BOTÃO SALVAR
        ///


        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (VerificaControles())
            {
                ALUNO oAluno = new ALUNO();

                oAluno.NOME      = txtNome.Text;
                oAluno.SOBRENOME = txtSobreNome.Text;
                oAluno.NASC      = dtpNasc.Value;
                oAluno.CPF       = txtCPF.Text;
                oAluno.ENDERECO  = txtEnd.Text;
                oAluno.BAIRRO    = txtBairro.Text;
                oAluno.CIDADE    = txtCidade.Text;
                oAluno.UF        = cmbUF.SelectedItem.ToString();
                oAluno.PAIS      = cmbPais.SelectedItem.ToString();
                oAluno.CEP       = txtCEP.Text;
                oAluno.TEL_RES   = txtTelRes.Text;
                oAluno.TEL_CEL   = txtTelCel.Text;
                oAluno.EMAIL     = txtEmail.Text;

                CAluno.CAlunoClient oProxy = new CAluno.CAlunoClient();
                oProxy.Open();

                if (var == 0)
                {
                    try
                    {
                        if (oProxy.Cadastrar(oAluno))
                        {
                            MessageBox.Show("Cadastro realizado com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LimpaCampos();
                        }
                        else
                        {
                            if (MessageBox.Show("Aluno existente! Deseja carregar os dados do aluno?", "Atenção", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                            {
                                string var = oAluno.CPF;

                                btnSalvar.Enabled = false;

                                btnDeletar.Enabled = true;

                                btnAlterar.Enabled = true;



                                ALUNO xAluno = oProxy.SelecionarCPF(var);

                                int var2 = xAluno.ID_ALUNO;

                                txtNome.Text         = xAluno.NOME;
                                txtSobreNome.Text    = xAluno.SOBRENOME;
                                dtpNasc.Value        = xAluno.NASC;
                                txtCPF.Text          = xAluno.CPF;
                                txtEnd.Text          = xAluno.ENDERECO;
                                txtBairro.Text       = xAluno.BAIRRO;
                                txtCidade.Text       = xAluno.CIDADE;
                                cmbUF.SelectedItem   = xAluno.UF;
                                cmbPais.SelectedItem = xAluno.PAIS;
                                txtCEP.Text          = xAluno.CEP;
                                txtTelRes.Text       = xAluno.TEL_RES;
                                txtTelCel.Text       = xAluno.TEL_CEL;
                                txtEmail.Text        = xAluno.EMAIL;
                                txtID.Text           = Convert.ToString(var2);


                                DesabilitaCampos();
                            }
                            else
                            {
                                LimpaCampos();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    try
                    {
                        if (oProxy.Alterar(oAluno))
                        {
                            MessageBox.Show("Alteração realizada com sucesso!", "Confirmação", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            LimpaCampos();

                            btnAlterar.Enabled = false;

                            HabilitaCampos();

                            var = 0;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Preencha todos os campos!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }