Example #1
0
        virtual public Inquilino ObtenerPorId(int id)
        {
            Inquilino i = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdInquilino, Nombre, Apellido, Dni, Telefono, Email, Garante, TelGarante FROM Inquilinos" +
                             $" WHERE IdInquilino=@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();
                    if (reader.Read())
                    {
                        i = new Inquilino
                        {
                            IdInquilino = reader.GetInt32(0),
                            Nombre      = reader.GetString(1),
                            Apellido    = reader.GetString(2),
                            Dni         = reader.GetString(3),
                            Telefono    = reader.GetString(4),
                            Email       = reader.GetString(5),
                            Garante     = reader.GetString(6),
                            TelGarante  = reader.GetString(7),
                        };
                    }
                    connection.Close();
                }
            }
            return(i);
        }
Example #2
0
        public List <Inquilino> ObtenerTodos()
        {
            List <Inquilino> res = new List <Inquilino>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdInquilino, Nombre, Apellido, Dni, Telefono, Email, Garante, TelGarante" +
                             $" FROM Inquilinos";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Inquilino i = new Inquilino
                        {
                            IdInquilino = reader.GetInt32(0),
                            Nombre      = reader.GetString(1),
                            Apellido    = reader.GetString(2),
                            Dni         = reader.GetString(3),
                            Telefono    = reader["Telefono"].ToString(),
                            Email       = reader.GetString(5),
                            Garante     = reader.GetString(6),
                            TelGarante  = reader.GetString(7),
                        };
                        res.Add(i);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
Example #3
0
        public int Alta(Inquilino i)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"INSERT INTO Inquilinos (Nombre, Apellido, Dni, Telefono, Email, Garante, TelGarante) " +
                             $"VALUES (@nombre, @apellido, @dni, @telefono, @email, @garante, @telGarante)";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@nombre", i.Nombre);
                    command.Parameters.AddWithValue("@apellido", i.Apellido);
                    command.Parameters.AddWithValue("@dni", i.Dni);
                    command.Parameters.AddWithValue("@telefono", i.Telefono);
                    command.Parameters.AddWithValue("@email", i.Email);
                    command.Parameters.AddWithValue("@garante", i.Garante);
                    command.Parameters.AddWithValue("@telGarante", i.TelGarante);
                    connection.Open();
                    res           = Convert.ToInt32(command.ExecuteScalar());
                    i.IdInquilino = res;
                    connection.Close();
                }
            }
            return(res);
        }
Example #4
0
        public int Modificar(Inquilino i)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"UPDATE Inquilinos SET Nombre=@nombre, Apellido=@apellido, Dni=@dni, Telefono=@telefono, Email=@email, Garante=@garante, TelGarante=@telGarante " +
                             $"WHERE IdInquilino = @id";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    command.Parameters.AddWithValue("@nombre", i.Nombre);
                    command.Parameters.AddWithValue("@apellido", i.Apellido);
                    command.Parameters.AddWithValue("@dni", i.Dni);
                    command.Parameters.AddWithValue("@telefono", i.Telefono);
                    command.Parameters.AddWithValue("@email", i.Email);
                    command.Parameters.AddWithValue("@garante", i.Garante);
                    command.Parameters.AddWithValue("@telGarante", i.TelGarante);
                    command.Parameters.AddWithValue("@id", i.IdInquilino);

                    connection.Open();
                    res = command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            return(res);
        }