public static Model.TipoOcorrencia BuscarPorId(int clienteId) { using (MySqlConnection conn = new MySqlConnection(strConection)) { conn.Open(); using (MySqlCommand cmd = new MySqlCommand()) { cmd.Connection = conn; cmd.CommandText = @"SELECT * FROM tipoOcorrencia WHERE id = ?id"; cmd.Parameters.AddWithValue("?id", clienteId); MySqlDataReader reader = cmd.ExecuteReader(); Model.TipoOcorrencia retorno = new Model.TipoOcorrencia(); while (reader.Read()) { retorno.Id = (int)reader["Id"]; retorno.Descricao = (string)reader["descricao"]; } return(retorno); } } }
public static void Salvar(Model.TipoOcorrencia tipoOcorrencia) { using (MySqlConnection conn = new MySqlConnection(strConection)) { conn.Open(); using (MySqlCommand cmd = new MySqlCommand()) { cmd.Connection = conn; if (tipoOcorrencia.Id == 0) { cmd.CommandText = @"INSERT INTO tipoOcorrencia (descricao) VALUES (?descricao);"; } else { cmd.CommandText = @"UPDATE tipoOcorrencia SET descricao = ?descricao WHERE id = ?id;"; } cmd.Parameters.AddWithValue("?descricao", tipoOcorrencia.Descricao); cmd.Parameters.AddWithValue("?id", tipoOcorrencia.Id); cmd.ExecuteNonQuery(); } } }
public ActionResult Create(Model.TipoOcorrencia ocorrencia) { try { Control.TipoOcorrenciaDAO.Salvar(ocorrencia); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, Model.TipoOcorrencia tipoOcorrencia) { try { // TODO: Add update logic here Control.TipoOcorrenciaDAO.Salvar(tipoOcorrencia); return(RedirectToAction("Index")); } catch { return(View()); } }