using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public class Album
{
	private string title;
	private string artist;
	private string genre;
	private string coverArtFile;

	public string Title { get { return title; } }
	public string Artist { get { return artist; } }
	public string Genre { get { return genre; } }
	public string CoverArtFile { get { return coverArtFile; } }

	public Album(
		string title,
		string artist,
		string genre,
		string coverArtFile)
	{
		this.title = title;		
		this.artist = artist;
		this.genre = genre;
		this.coverArtFile = coverArtFile;
	}
}

public class Albums
{
	private SqlConnection connection;
	private SqlCommand command;

	public Albums()
	{
		connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MusicStoreDBConnection"].ConnectionString);
		command = new SqlCommand();
		command.Connection = connection;
		command.CommandType = CommandType.Text;
		connection.Open();
	}

	public List<Album> Get()
	{
		command.CommandText = String.Format(CultureInfo.InvariantCulture, @"
SELECT [AlbumTitle], [ArtistName], [GenreName], [CoverArtFile]
FROM [AlbumDetails]");

		List<Album> albums = new List<Album>();

		using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
		{		
			
			while (reader.Read())
			{
				albums.Add(new Album(
					(string)reader["AlbumTitle"],
					(string)reader["ArtistName"],
					(string)reader["GenreName"],
					(string)reader["CoverArtFile"]));
			}
		}

		return albums;
	}
}
