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); } }
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 { } }
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()); }
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); } }
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); } }
/// <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)); } }
/// <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()); } }
/// <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)); } }
public IActionResult Cadastrar([FromForm] Mae mae) { if (ModelState.IsValid) { _db.Maes.Add(mae); _db.SaveChanges(); return(RedirectToAction("index", mae)); } return(View()); }
/// <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)); } }
public ActionResult Eliminar(Mae mae) { var resultado = daoMae.Eliminar(mae); if (resultado > -1) { return(RedirectToAction("Index")); } return(View()); }
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)); }
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); } }
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)); }
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)); }
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); } }
static void Main(string[] args) { Mae mae = new Mae("não"); Console.WriteLine(mae.Amamentar); }
public IActionResult Atualizar([FromForm] Mae mae) { return(View()); }
public DAOMae() { mae = new Mae(); }