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

namespace CallCenterApi.DAL
{
    public class T_Sys_BanCallOut
    {
        public bool Add(Model.T_Sys_BanCallOut model)
        {
            var sql = "insert into T_Sys_BanCallOut (F_DeptId,StartTime1,StartTime2,EndTime1,EndTime2) values (@F_DeptId,@StartTime1,@StartTime2,@EndTime1,@EndTime2)";
            return DbHelperSQL.ExecuteSql(sql, new SqlParameter[] {
               new SqlParameter("@F_DeptId", model.F_DeptId),
               new SqlParameter("@StartTime1", model.StartTime1),
               new SqlParameter("@EndTime1", model.EndTime1),
               new SqlParameter("@StartTime2", model.StartTime2),
               new SqlParameter("@EndTime2", model.EndTime2)
            }) > 0;
        }
        public bool Update(Model.T_Sys_BanCallOut model)
        {
            var sql = "update T_Sys_BanCallOut set StartTime1=@StartTime1,EndTime1=@EndTime1,StartTime2=@StartTime2,EndTime=@EndTime2 where F_Id=@F_Id ";
            return DbHelperSQL.ExecuteSql(sql, new SqlParameter[] {
               new SqlParameter("@F_Id", model.F_Id),
               new SqlParameter("@StartTime1", model.StartTime1),
               new SqlParameter("@EndTime1", model.EndTime1),
               new SqlParameter("@StartTime2", model.StartTime2),
               new SqlParameter("@EndTime2", model.EndTime2)
            }) > 0;
        }
        public Model.T_Sys_BanCallOut GetModel(int deptId)
        {
            Model.T_Sys_BanCallOut model = new Model.T_Sys_BanCallOut();
            var sql = "select F_Id,F_DeptId,StartTime1,StartTime2,EndTime1,EndTime2	from T_Sys_BanCallOut where F_DeptId ";
            var dt = DbHelperSQL.Query(sql, new SqlParameter("@F_DeptId", deptId)).Tables[0];
            if (dt.Rows.Count > 0)
            {
                model.F_Id = dt.Rows[0]["F_Id"] == DBNull.Value ? 0 : Convert.ToInt32(dt.Rows[0]["F_Id"]);
                model.F_DeptId = dt.Rows[0]["F_DeptId"] == DBNull.Value ? 0 : Convert.ToInt32(dt.Rows[0]["F_DeptId"].ToString());
                model.StartTime1 = dt.Rows[0]["StartTime1"] == DBNull.Value ? null : (DateTime?)DateTime.Parse(dt.Rows[0]["StartTime1"].ToString());
                model.StartTime2 = dt.Rows[0]["StartTime2"] == DBNull.Value ? null : (DateTime?)DateTime.Parse(dt.Rows[0]["StartTime2"].ToString());
                model.EndTime1 = dt.Rows[0]["EndTime1"] == DBNull.Value ? null : (DateTime?)DateTime.Parse(dt.Rows[0]["EndTime1"].ToString());
                model.EndTime2 = dt.Rows[0]["EndTime2"] == DBNull.Value ? null : (DateTime?)DateTime.Parse(dt.Rows[0]["EndTime2"].ToString());
                return model;
            }
            return null;

        }
    }
}
