using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DAL;

namespace BLL
{
    public class Kala
    {
        string _kalaid;
        string _kalaname;
        string _price;
        string _groupname;
        string _vahed;

        public Kala()
        {

        }

        public string kalaid
        {
            get
            {
                return _kalaid;
            }
            set
            {
                this._kalaid = value;

            }
        }
        public string price
        {
            get
            {
                return _price;
            }
            set
            {
                this._price = value;

            }
        }
        public string kalaname
        {
            get
            {
                return _kalaname;
            }
            set
            {
                this._kalaname = value;

            }
        }
        public string GroupName
        {
            get
            {
                return _groupname;
            }
            set
            {
                _groupname = value;
            }
        }
        public string Vahed
        {
            get
            {
                return _vahed;
            }
            set
            {
                _vahed = value;
            }
        }

        public void Insert()
        {
            KalaMethods methods = new KalaMethods();
            methods.Insert(this.kalaid, this.kalaname, this.price,this.GroupName,this.Vahed);
        }

        public void Update()
        {
            KalaMethods methods = new KalaMethods();
            methods.Update(this.kalaid, this.kalaname, this.price, this.GroupName, this.Vahed);
        }

        public void Delete()
        {
            KalaMethods methods = new KalaMethods();
            methods.Delete(this.kalaid);
        }

        public static List<Kala> GetAllKalas()
        {
            KalaMethods methods = new KalaMethods();
            return GetAllKalas((IDataReader)methods.SelectAll());
        }

        public static List<Kala> GetKala(long kalaid)
        {
            KalaMethods methods = new KalaMethods();
            return GetAllKalas((IDataReader)methods.Select(kalaid));
        }

        private static List<Kala> GetAllKalas(IDataReader reader)
        {
            List<Kala> tempList = new List<Kala>();
            while (reader.Read())
            {
                try
                {
                    Kala temp = new Kala
                    {
                        kalaid = reader["kalaid"].ToString(),
                        kalaname = reader["kalaname"].ToString(),
                        price = reader["price"].ToString(),
                        GroupName=reader["groupname"].ToString(),
                        Vahed=reader["vahed"].ToString()
                    };
                    tempList.Add(temp);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message.ToString());
                }
            }
            return tempList;
        }

    }

    public class kalaGroup
    {
        string _groupname;
        public string GroupName
        {
            get
            {
                return _groupname;
            }
            set
            {
                _groupname = value;
            }
        }
        public kalaGroup()
        {
        }

        private static List<kalaGroup> GetAllGroups(IDataReader reader)
        {
            List<kalaGroup> tempList = new List<kalaGroup>();
            while (reader.Read())
            {
                try
                {
                    kalaGroup temp = new kalaGroup
                    {
                        GroupName=reader["groupname"].ToString()
                    };
                    tempList.Add(temp);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message.ToString());
                }
            }
            return tempList;
        }

        public static List<kalaGroup> GetAllGroups()
        {
            KalaMethods methods = new KalaMethods();
            return GetAllGroups((IDataReader)methods.SelectAllKalaGroups());
        }
    }

}

