using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CallCenterApi.Model;

namespace CallCenterApi.BLL
{
    public class T_Cus_CustomerField
    {
        private readonly DAL.T_Cus_CustomerField dal = new DAL.T_Cus_CustomerField();
        public List<Model.T_Cus_CustomerField> DataTableToList(DataTable dt)
        {
            List<Model.T_Cus_CustomerField> list = new List<Model.T_Cus_CustomerField>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    list.Add(new Model.T_Cus_CustomerField
                    {
                        F_Id = Convert.ToInt32(row["F_Id"]),
                        F_FieldType = Convert.ToInt32(row["F_FieldType"]),
                        F_FieldId = Convert.ToInt32(row["F_FieldId"]),
                        F_Name = row["F_Name"].ToString(),
                        F_DBTypeName = row["F_DBTypeName"].ToString(),
                        F_DBFieldName = row["F_DBFieldName"].ToString(),
                        F_Sort = row["F_Sort"] == DBNull.Value ? 0 : Convert.ToInt32(row["F_Sort"]),
                        F_CharLength = row["F_CharLength"] == DBNull.Value ? 0 : Convert.ToInt32(row["F_CharLength"]),
                        F_IsNecessary = row["F_IsNecessary"] == DBNull.Value ? 0 : Convert.ToInt32(row["F_IsNecessary"]),
                        F_IsExportOrInput = row["F_IsExportOrInput"] == DBNull.Value ? 0 : Convert.ToInt32(row["F_IsExportOrInput"]),
                        F_IsShowOnList = row["F_IsShowOnList"] == DBNull.Value ? 0 : Convert.ToInt32(row["F_IsShowOnList"]),
                        F_IsShowOnScrean = row["F_IsShowOnScrean"] == DBNull.Value ? 0 : Convert.ToInt32(row["F_IsShowOnScrean"]),
                        F_Search = row["F_Search"] == DBNull.Value ? 0 : Convert.ToInt32(row["F_Search"]),


                    });

                }
            }
            return list;
        }

        public Model.T_Cus_CustomerField GetModel(int id)
        {
            return dal.GetModel(id);
        }

        public bool Update(Model.T_Cus_CustomerField model)
        {
            return dal.Update(model);
        }

        public int Add(Model.T_Cus_CustomerField model)
        {
            return dal.Add(model);
        }

        public bool Delete(int id)
        {
            return dal.Delete(id);
        }

        public List<Model.T_Cus_CustomerField> GetList()
        {
            var dt = dal.GetList();
            return DataTableToList(dt);

        }
    }
}
