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

namespace BLL
{
    public class Sandogh
    {
        string _sname;
        string _mojodi;

        public Sandogh() { }

        public string SandoghName
        {
            set
            {
                _sname = value;
            }
            get
            {
                return _sname;
            }
        }
        public string Mojodi
        {
            set
            {
                _mojodi = value;
            }
            get { return _mojodi; }
        }

        public void Insert()
        {
            SandoghMethods method = new SandoghMethods();
            method.Insert(this.SandoghName, this.Mojodi);
        }

        public void Update()
        {
            SandoghMethods method = new SandoghMethods();
            method.Update(this.SandoghName, this.Mojodi);
        }

        public void Delete()
        {
            SandoghMethods method = new SandoghMethods();
            method.Delete(this.SandoghName);
        }

        private static List<Sandogh> GetAllSandoghs(IDataReader reader)
        {
            List<Sandogh> tempList = new List<Sandogh>();
            while (reader.Read())
            {
                try
                {
                    Sandogh temp = new Sandogh
                    {
                        SandoghName = reader["sname"].ToString(),
                        Mojodi = reader["mojodi"].ToString(),
                    };
                    tempList.Add(temp);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message.ToString());
                }
            }
            return tempList;
        }

        public static List<Sandogh> GetAllSandoghs()
        {
            SandoghMethods methods = new SandoghMethods();
            return GetAllSandoghs((IDataReader)methods.SelectAll());
        }

        public static List<Sandogh> GetSandogh(string sname)
        {
            SandoghMethods methods = new SandoghMethods();
            return GetAllSandoghs((IDataReader)methods.Select(sname));
        }
    }
}
