using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyTunes.Common.DAL;
using MyTunes.Common.DAL.MyTunesDataSetTableAdapters;

namespace MyTunes.Common.BLL
{
    [System.ComponentModel.DataObject]
    public class ArtistBLL
    {
        private ArtistTableAdapter _artistAdapter = null;

        protected ArtistTableAdapter Adpater
        {
            get
            {
                if (_artistAdapter == null)
                    _artistAdapter = new ArtistTableAdapter();
                return _artistAdapter;
            }
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public MyTunesDataSet.ArtistDataTable GetArtists()
        {
            return Adpater.GetArtists();
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public bool AddArtist(string artistName)
        {
            MyTunesDataSet.ArtistDataTable artists = new MyTunesDataSet.ArtistDataTable();
            MyTunesDataSet.ArtistRow artist = artists.NewArtistRow();
            artist.artist = artistName;
            artists.AddArtistRow(artist);
            int rowsAffected = Adpater.Update(artists);
            return (rowsAffected == 1);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public bool UpdateArtist(int artistID, string artistName)
        {
            MyTunesDataSet.ArtistDataTable artists = Adpater.GetArtistsByArtistID(artistID);
            if (artists.Count == 0)
                return false;
            MyTunesDataSet.ArtistRow artist = artists[0];
            artist.artist = artistName;
            int rowsAffected = Adpater.Update(artist);
            return (rowsAffected == 1);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public bool DeleteArtist(int artistID, byte[] changed)
        {
            int rowsAffected = Adpater.Delete(artistID, changed);
            return (rowsAffected == 1);
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public bool DeleteArtist(int artistID)
        {
            MyTunesDataSet.ArtistDataTable artists = Adpater.GetArtistsByArtistID(artistID);
            if (artists.Count == 0)
                return false;
            return DeleteArtist(artistID, artists[0].changed);
        }
    }
}