示例#1
0
        public List <Mae> PesquisarPorNome(string nome)
        {
            try
            {
                var sql = "SELECT * FROM mae WEHERE nome LIKE '%" + nome + "%' ";

                command    = new MySqlCommand(sql, connection);
                dataReader = command.ExecuteReader(); //receber o resultado da consulta
                List <Mae> listaMae = new List <Mae>();


                if (dataReader.Read())
                {
                    Mae mae = new Mae();
                    mae.Id         = Convert.ToInt32(dataReader["id"]);
                    mae.Nome       = dataReader["nome"].ToString();
                    mae.dtCadastro = dataReader["dtCadastro"].ToString();
                    listaMae.Add(mae);
                }
                return(listaMae);
            }
            catch (Exception erro)
            {
                throw new Exception("Erro ao registrar dado" + erro);
            }
        }
示例#2
0
        protected void btnCadastrarMae(object sender, EventArgs e)
        {
            try
            {
                Mae    mae    = new Mae();
                MaeDal maeDal = new MaeDal();
                mae.Nome = nome.Text;
                maeDal.Salvar(mae);

                nome.Text = "";


                string msg = "Mae " + mae.Nome + "-" + " foi cadastrado com Sucesso";
                lblMensagem.Attributes.CssStyle.Add("color", "green");
                lblMensagem.Text = msg;

                //Thread.Sleep(5000);

                // Response.Redirect("http://127.0.0.1:8080/Pages/MaeCadastro.aspx");
            }
            catch (Exception erro)
            {
                lblMensagem.Text = erro.Message;
            }
            finally
            {
            }
        }
示例#3
0
        public IActionResult Update(int id, [FromBody] Mae mae)
        {
            if (mae == null || mae.Id != id)
            {
                return(BadRequest());
            }

            var ma = _context.Maes.FirstOrDefault(m => m.Id == id);

            if (ma == null)
            {
                return(NotFound());
            }

            ma.Nome              = mae.Nome;
            ma.IdadeMae          = mae.IdadeMae;
            ma.escolaridade      = mae.escolaridade;
            ma.EstadoCivil       = mae.EstadoCivil;
            ma.QuantFilhosMortos = mae.QuantFilhosMortos;
            ma.QuantFilhosVivos  = mae.QuantFilhosVivos;

            _context.Maes.Update(ma);
            _context.SaveChanges();
            return(new NoContentResult());
        }
示例#4
0
        public Mae PesquisarPorId(int id)
        {
            try
            {
                var sql = "SELECT * FROM mae WHERE id = @id";
                command = new MySqlCommand(sql, connection);
                command.Parameters.AddWithValue("@id", id);
                dataReader = command.ExecuteReader();
                //command.ExecuteNonQuery();


                Mae mae = new Mae();

                if (dataReader.Read())
                {
                    mae.Id         = Convert.ToInt32(dataReader["id"]);
                    mae.Nome       = dataReader["nome"].ToString();
                    mae.dtCadsatro = dataReader["dtCadastro"].ToString();
                }
                return(mae);
            }
            catch (Exception erro)
            {
                throw new Exception("Erro de insercao MAe" + erro);
            }
        }
示例#5
0
        public List <Mae> PesquisarPorNome(string nome)
        {
            try
            {
                var sql = "SELECT * FROM mae WHERE nome LIKE '%" + nome + "%'";
                command    = new MySqlCommand(sql, connection);
                dataReader = command.ExecuteReader();

                List <Mae> listaMae = new List <Mae>();

                while (dataReader.Read())
                {
                    Mae mae = new Mae();
                    mae.Id         = Convert.ToInt32(dataReader["id"]);
                    mae.Nome       = dataReader["nome"].ToString();
                    mae.dtCadsatro = dataReader["dtCadastro"].ToString();

                    listaMae.Add(mae);
                }
                return(listaMae);
            }
            catch (Exception erro)
            {
                throw new Exception("Erro de insercao Mae" + erro);
            }
        }
示例#6
0
 /// <summary>
 /// Para eliminar um registo existente de acordo ao id
 /// </summary>
 /// <param name="mae"></param>
 /// <returns></returns>
 public int Eliminar(Mae mae)
 {
     using (var db = new MySqlConnection(ConfigurationManager.ConnectionStrings["estudantescn"].ConnectionString))
     {
         string sql = $"delete from  mae where {nameof(mae.Id)}={mae.Id}";
         return(db.Execute(sql, commandType: CommandType.Text));
     }
 }
示例#7
0
 /// <summary>
 /// Para obter um único registo de acordo ao id
 /// </summary>
 /// <param name="mae"></param>
 /// <returns></returns>
 public Mae ObterPeloId(Mae mae)
 {
     using (var db = new MySqlConnection(ConfigurationManager.ConnectionStrings["estudantescn"].ConnectionString))
     {
         string sql = $"select {nameof(mae.Id)},{nameof(mae.NomeCompleto)},{nameof(mae.CPF)}," +
                      $"{nameof(mae.DataPreferencialPagamento)}  from mae where id={mae.Id}";
         return(db.Query <Mae>(sql, commandType: CommandType.Text).FirstOrDefault());
     }
 }
示例#8
0
        /// <summary>
        /// Para inserir um novo registo
        /// </summary>
        /// <param name="mae"></param>
        /// <returns></returns>
        public int Inserir(Mae mae)
        {
            using (var db = new MySqlConnection(ConfigurationManager.ConnectionStrings["estudantescn"].ConnectionString))
            {
                string sql = $"INSERT INTO mae ({nameof(mae.NomeCompleto)}, {nameof(mae.CPF)}, {nameof(mae.DataPreferencialPagamento)})" +
                             $" VALUES ('{mae.NomeCompleto}', '{mae.CPF}', '{mae.DataPreferencialPagamento.Value.ToString("yyyy-MM-dd")}')";

                return(db.Execute(sql, commandType: CommandType.Text));
            }
        }
示例#9
0
 public IActionResult Cadastrar([FromForm] Mae mae)
 {
     if (ModelState.IsValid)
     {
         _db.Maes.Add(mae);
         _db.SaveChanges();
         return(RedirectToAction("index", mae));
     }
     return(View());
 }
示例#10
0
 /// <summary>
 /// Para actualizar um registo existente de acordo ao id
 /// </summary>
 /// <param name="mae"></param>
 /// <returns></returns>
 public int Actualizar(Mae mae)
 {
     using (var db = new MySqlConnection(ConfigurationManager.ConnectionStrings["estudantescn"].ConnectionString))
     {
         string sql = $"update mae set {nameof(mae.NomeCompleto)}='{mae.NomeCompleto}', {nameof(mae.CPF)}='{mae.CPF}'," +
                      $"{nameof(mae.DataPreferencialPagamento)}='{mae.DataPreferencialPagamento.Value.ToString("yyyy-MM-dd")}' " +
                      $" where {nameof(mae.Id)}={mae.Id}";
         return(db.Execute(sql, commandType: CommandType.Text));
     }
 }
示例#11
0
        public ActionResult Eliminar(Mae mae)
        {
            var resultado = daoMae.Eliminar(mae);

            if (resultado > -1)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }
示例#12
0
 public ActionResult Editar([Bind(Include = "id,nomeCompleto,cpf,dataPreferencialPagamento")] Mae mae)
 {
     if (ModelState.IsValid)
     {
         var resultado = daoMae.Actualizar(mae);
         if (resultado > -1)
         {
             return(RedirectToAction("Index", "Mae"));
         }
     }
     return(View(mae));
 }
示例#13
0
        public void Salvar(Mae mae)
        {
            try
            {
                var sql = "INSERT INTO mae(nome, dtCadastro)" +
                          "VALUES(@nome, CURDATE())";

                command = new MySqlCommand(sql, connection);
                command.Parameters.AddWithValue("@nome", mae.Nome);
                command.ExecuteNonQuery();
            }
            catch (Exception erro)
            {
                throw new Exception("Erro de insercao" + erro);
            }
        }
示例#14
0
        public IActionResult Create([FromBody] Mae mae)
        {
            if (mae == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _context.Maes.Add(mae);
            _context.SaveChanges();

            return(CreatedAtRoute("Mae", new { id = mae.Id }, mae));
        }
示例#15
0
 public ActionResult Cadastrar([Bind(Include = "id,nomeCompleto,cpf,dataPreferencialPagamento")] Mae mae)
 {
     if (ModelState.IsValid)
     {
         if (CpfUtils.IsValidCPF(mae.CPF) && !daoMae.VerificarExistenciaCPF(mae.CPF))
         {
             var resultado = daoMae.Inserir(mae);
             if (resultado > -1)
             {
                 return(RedirectToAction("Index", "Mae"));
             }
         }
         else
         {
             ModelState.AddModelError(nameof(mae.CPF), "CPF incorrecto");
             return(View(mae));
         }
     }
     return(View(mae));
 }
示例#16
0
        public Mae PesquisarPorId(int id)
        {
            try
            {
                var sql = "SELECT * FROM mae WEHERE id = @id";

                command = new MySqlCommand(sql, connection);
                command.Parameters.AddWithValue("@id", id);
                dataReader = command.ExecuteReader(); //receber o resultado da consulta
                Mae mae = new Mae();
                if (dataReader.Read())
                {
                    mae.Id         = Convert.ToInt32(dataReader["id"]);
                    mae.Nome       = dataReader["nome"].ToString();
                    mae.dtCadastro = dataReader["dtCadastro"].ToString();
                }
                return(mae);
            }
            catch (Exception erro)
            {
                throw new Exception("Erro ao registrar dado" + erro);
            }
        }
示例#17
0
        static void Main(string[] args)
        {
            Mae mae = new Mae("não");

            Console.WriteLine(mae.Amamentar);
        }
示例#18
0
 public IActionResult Atualizar([FromForm] Mae mae)
 {
     return(View());
 }
示例#19
0
 public DAOMae()
 {
     mae = new Mae();
 }