using System.Collections.Generic;
using System.Data.SqlClient;
using Baza_Reklam.Classes.Model;

namespace Baza_Reklam.Classes.Repositories
{
    public class AdLocationRepository : Repository<AdLocation>
    {
        //private readonly string _connectionString;

        public AdLocationRepository(string connectionString)
            : base(connectionString)
        {
        }

        public override List<AdLocation> FindAll()
        {
            const string query = "SELECT Id, Text FROM dbo.ReklamaLokalizacja ORDER BY Id";
            List<AdLocation> adPlacements = new List<AdLocation>();

            try
            {
                _connection.Open();
                _command = new SqlCommand(query, _connection);
                _reader = _command.ExecuteReader();
                if (_reader != null)
                {
                    while (_reader.Read())
                        adPlacements.Add(new AdLocation(_reader.GetInt32(0), _reader.GetString(1)));
                }
            }
            finally
            {
                CleanUp();

            }
            return adPlacements;
        }
    }
}