private void Inserir(Estado estado) { using (contexto = new Contexto()) { string strQuery = string.Format(" INSERT INTO ESTADO(NomeEstado) VALUES('{0}') ", estado.NomeEstado); contexto.ExecutaComando(strQuery); } }
private void Alterar(Estado estado) { using (contexto = new Contexto()) { string strQuery = " UPDATE ESTADO SET "; strQuery += string.Format(" NomeEstado = '{0}' ", estado.NomeEstado); strQuery += string.Format(" WHERE IdEstado = {0} ", estado.IdEstado); contexto.ExecutaComando(strQuery); } }
public void Salvar(Estado estado) { if (estado.IdEstado > 0) { Alterar(estado); } else { Inserir(estado); } }
public ActionResult Cadastrar(Estado estado) { if (ModelState.IsValid) { aplicacao.Salvar(estado); return RedirectToAction("Index"); } else { return View(estado); } }
private List<Estado> TransformaDataReaderEmLista(SqlDataReader reader) { var estados = new List<Estado>(); while (reader.Read()) { Estado estado = new Estado(); estado.IdEstado = int.Parse(reader["IdEstado"].ToString()); estado.NomeEstado = reader["NomeEstado"].ToString(); estados.Add(estado); } reader.Close(); return estados; }