public IList <Inquilino> ObtenerTodos() { IList <Inquilino> res = new List <Inquilino>(); using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT InquilinoId, Nombre, Apellido, Dni, Telefono, Email, EstaPublicado, EstaHabilitado" + $" FROM Inquilinos"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { Inquilino p = new Inquilino { InquilinoId = reader.GetInt32(0), Nombre = reader.GetString(1), Apellido = reader.GetString(2), Dni = reader.GetString(3), Telefono = reader.GetString(4), Email = reader.GetString(5), EstaPublicado = reader.GetBoolean(6), EstaHabilitado = reader.GetBoolean(7), }; res.Add(p); } connection.Close(); } } return(res); }
public Inquilino ObtenerPorId(int id) { Inquilino p = null; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"SELECT InquilinoId, Nombre, Apellido, Dni, Telefono, Email, EstaPublicado, EstaHabilitado FROM Inquilinos" + $" WHERE InquilinoId=@id"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.Add("@id", SqlDbType.Int).Value = id; command.CommandType = CommandType.Text; connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { p = new Inquilino { InquilinoId = reader.GetInt32(0), Nombre = reader.GetString(1), Apellido = reader.GetString(2), Dni = reader.GetString(3), Telefono = reader.GetString(4), Email = reader.GetString(5), EstaPublicado = reader.GetBoolean(6), EstaHabilitado = reader.GetBoolean(7), }; return(p); } connection.Close(); } } return(p); }
public int Modificacion(Inquilino p) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"UPDATE Inquilinos SET Nombre='{p.Nombre}', Apellido='{p.Apellido}', Dni='{p.Dni}', Telefono='{p.Telefono}', Email='{p.Email}' , EstaPublicado='{p.EstaPublicado}', EstaHabilitado='{p.EstaHabilitado}'" + $"WHERE InquilinoId = {p.InquilinoId}"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); res = command.ExecuteNonQuery(); connection.Close(); } } return(res); }
public int Alta(Inquilino p) { int res = -1; using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = $"INSERT INTO Inquilinos (Nombre, Apellido, Dni, Telefono, Email, EstaPublicado,EstaHabilitado) " + $"VALUES ('{p.Nombre}', '{p.Apellido}','{p.Dni}','{p.Telefono}','{p.Email}' ,'1','1')"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.CommandType = CommandType.Text; connection.Open(); res = command.ExecuteNonQuery(); command.CommandText = "SELECT SCOPE_IDENTITY()"; var id = command.ExecuteScalar(); p.InquilinoId = Convert.ToInt32(id); connection.Close(); } } return(res); }