public int DeleteDepartamento(int Id) { vsystem_ndcEntities db = new vsystem_ndcEntities(); tbl_departamento depar = new tbl_departamento(); depar = db.tbl_departamento.Find(Id); if (depar != null) { try { db.tbl_departamento.Remove(depar); db.SaveChanges(); return 1; } catch (SystemException) { return 2; } } return 0; }
public void PostDepartmento(tbl_departamento departamento) { vsystem_ndcEntities db = new vsystem_ndcEntities(); tbl_departamento Departamento = new tbl_departamento(); Departamento.departamentoid = departamento.departamentoid; Departamento.descripcion = departamento.descripcion; Departamento.activo = departamento.activo; db.tbl_departamento.Add(departamento); db.SaveChanges(); }
public List<tbl_departamento> GetDepartamentosList() { string connectionString = "SERVER=104.236.126.219;DATABASE=vsystem_ndc;UID=ndc;PASSWORD=ndc01;"; List<tbl_departamento> list = new List<tbl_departamento>(); tbl_departamento temp; MySqlConnection connection = new MySqlConnection(connectionString); string query = "SELECT * FROM tbl_departamento"; connection.Open(); MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { temp = new tbl_departamento(); temp.activo = (dataReader["activo"].ToString().Equals("1") ? true : false); temp.descripcion = dataReader["descripcion"].ToString(); temp.departamentoid = (int)dataReader["departamentoid"]; list.Add(temp); } dataReader.Close(); connection.Close(); return list; }