using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Aram_CRM_Project.BLL.Entity;

namespace Aram_CRM_Project.BLL
{
    class CityStateCRUD : Aram_CRM_Project.DAL.DA
    {
        public int InsertCityState(CityState CityStateVar)
        {
            try
            {
                base.SQL = "SP_InsertCityState";
                base.InitializeCommand();
                base.AddParameter("@Name", CityStateVar.Name);
                base.AddParameter("@Comment", CityStateVar.Comment);
                return base.ExecuteStoredProcedure();
            }
            catch(Exception exp)
            {
                if (exp.Message.Contains("UNIQUE KEY") && exp.Message.Contains("duplicate"))
                    return -1;
                else
                    return 0;
            }
        }

        public int UpdateCityState(CityState CityStateVar)
        {
            try
            {
                base.SQL = "SP_UpdateCityState";
                base.InitializeCommand();
                base.AddParameter("@Id", CityStateVar.Id);
                base.AddParameter("@Name", CityStateVar.Name);
                base.AddParameter("@Comment", CityStateVar.Comment);
                return base.ExecuteStoredProcedure();
            }
            catch (Exception exp)
            {
                if (exp.Message.Contains("UNIQUE KEY") && exp.Message.Contains("duplicate"))
                    return -1;
                else
                    return 0;
            }
        }

        public int DeleteCityState(string Id)
        {
            try
            {
                base.SQL = "SP_DeleteCityState";
                base.InitializeCommand();
                base.AddParameter("@Id", Id);
                return base.ExecuteStoredProcedure();
            }
            catch(Exception exp)
            {
                if (exp.Message.Contains("COLUMN REFERENCE"))
                    return -1;
                else
                    return 0;
            }
        }

        public CityState ReadCityState(string Id)
        {
            try
            {
                CityState CityStateVar = new CityState();
                DataTable dtTemp = new DataTable();
                base.SQL = "SP_ReadCityState";
                base.InitializeCommand();
                base.AddParameter("@Id", Id);
                base.FillDataTable(dtTemp);
                CityStateVar.Id = dtTemp.Rows[0]["Id"].ToString();
                CityStateVar.Name = dtTemp.Rows[0]["Name"].ToString();
                CityStateVar.Comment = dtTemp.Rows[0]["Comment"].ToString();
                dtTemp.Dispose();
                return CityStateVar;
            }
            catch (Exception exp)
            {
                return null;
            }
        }

        public DataTable SearchCityState(string Name)
        {
            try
            {
                DataTable dtTemp = new DataTable();
                base.SQL = "SP_SearchCityState";
                base.InitializeCommand();
                base.AddParameter("@Name", Name);
                base.FillDataTable(dtTemp);
                return dtTemp;
            }
            catch (Exception exp)
            {
                return null;
            }
        }

        public DataTable ReportCityState(string Name)
        {
            try
            {
                DataTable dtTemp = new DataTable();
                base.SQL = "SP_ReportCityState";
                base.InitializeCommand();
                base.AddParameter("@Name", Name);
                base.FillDataTable(dtTemp);
                return dtTemp;
            }
            catch (Exception exp)
            {
                return null;
            }
        }
    }
}
