public IList <Inquilino> ObtenerTodos()
        {
            IList <Inquilino> res = new List <Inquilino>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT Id, Nombre, Apellido, Dni, Telefono, Email, NombreGarante, DniGarante, TelefonoGarante" +
                             $" 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
                        {
                            Id              = reader.GetInt32(0),
                            Nombre          = reader.GetString(1),
                            Apellido        = reader.GetString(2),
                            Dni             = reader.GetString(3),
                            Telefono        = reader.GetString(4),
                            Email           = reader.GetString(5),
                            NombreGarante   = reader.GetString(6),
                            DniGarante      = reader.GetString(7),
                            TelefonoGarante = reader.GetString(8),
                        };
                        res.Add(p);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
        public int Alta(Inquilino e)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"INSERT INTO Inquilinos (Nombre, Apellido, Dni, Telefono, Email,NombreGarante,DniGarante,TelefonoGarante) " +
                             $"VALUES (@nombre, @apellido, @dni, @telefono, @email,@nombreGarante,@dniGarante,@telefonoGarante);" +
                             "SELECT SCOPE_IDENTITY();";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@nombre", e.Nombre);
                    command.Parameters.AddWithValue("@apellido", e.Apellido);
                    command.Parameters.AddWithValue("@dni", e.Dni);
                    command.Parameters.AddWithValue("@telefono", e.Telefono);
                    command.Parameters.AddWithValue("@email", e.Email);
                    command.Parameters.AddWithValue("@nombreGarante", e.NombreGarante);
                    command.Parameters.AddWithValue("@dniGarante", e.DniGarante);
                    command.Parameters.AddWithValue("@telefonoGarante", e.TelefonoGarante);

                    connection.Open();

                    res  = Convert.ToInt32(command.ExecuteScalar());
                    e.Id = res;
                    connection.Close();
                }
            }
            return(res);
        }
        public int Modificacion(Inquilino e)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"UPDATE Inquilinos SET " +
                             $"Nombre=@nombre, Apellido=@apellido, Dni=@dni, Telefono=@telefono, Email=@email,NombreGarante=@nombreGarante,DniGarante=@dniGarante,TelefonoGarante=@telefonoGarante" +
                             $" WHERE Id = @id";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@nombre", e.Nombre);
                    command.Parameters.AddWithValue("@apellido", e.Apellido);
                    command.Parameters.AddWithValue("@dni", e.Dni);
                    command.Parameters.AddWithValue("@telefono", e.Telefono);
                    command.Parameters.AddWithValue("@email", e.Email);
                    command.Parameters.AddWithValue("@nombreGarante", e.NombreGarante);
                    command.Parameters.AddWithValue("@dniGarante", e.DniGarante);
                    command.Parameters.AddWithValue("@telefonoGarante", e.TelefonoGarante);
                    command.Parameters.AddWithValue("@id", e.Id);
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            return(res);
        }
        public Inquilino ObtenerPorId(int id)
        {
            Inquilino p = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT Id, Nombre, Apellido, Dni, Telefono, Email, NombreGarante, DniGarante, TelefonoGarante FROM Inquilinos" +
                             $" WHERE Id=@id";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    command.Parameters.Add("@id", SqlDbType.Int).Value = id;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        p = new Inquilino
                        {
                            Id              = reader.GetInt32(0),
                            Nombre          = reader.GetString(1),
                            Apellido        = reader.GetString(2),
                            Dni             = reader.GetString(3),
                            Telefono        = reader.GetString(4),
                            Email           = reader.GetString(5),
                            NombreGarante   = reader.GetString(6),
                            DniGarante      = reader.GetString(7),
                            TelefonoGarante = reader.GetString(8),
                        };
                        return(p);
                    }
                    connection.Close();
                }
            }
            return(p);
        }